我和OWL文件,我可以浏览它并浏览类和属性,但我无法检索正确的ObjectProperty范围。 这是我的OWL文件的一部分:
<owl:ObjectProperty rdf:about="&aat;aat2209_located_in">
<rdfs:label xml:lang="en">located in</rdfs:label>
<rdfs:label xml:lang="it">si trova in</rdfs:label>
<rdfs:comment xml:lang="en">The property defines a relationship between places or places and things</rdfs:comment>
<rdfs:comment xml:lang="it">La proprietà definisce la relazione tra luoghi o tra luoghi e cose</rdfs:comment>
<rdfs:domain>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<rdf:Description rdf:about="&dbpedia-owl;Artwork"/>
<rdf:Description rdf:about="&dbpedia-owl;Cave"/>
</owl:unionOf>
</owl:Class>
</rdfs:domain>
<rdfs:range>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<rdf:Description rdf:about="&lodmt;ArchaeologicalSite"/>
<rdf:Description rdf:about="&dbpedia-owl;Building"/>
</owl:unionOf>
</owl:Class>
</rdfs:range>
</owl:ObjectProperty>
这是我探索OWL文件的代码的一部分
...
OntModel inf = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
InputStream in =getClass().getResourceAsStream("/"+DATA_IRI);
inf.read(in, "");
OntClass obj = inf.getOntClass(uri);
ExtendedIterator<OntProperty> propIter = obj.listDeclaredProperties(false);
if(propIter.hasNext()){
while (propIter.hasNext()) {
Set<PropertyModel> properties = new HashSet<PropertyModel>();
final OntProperty ontProperty = (OntProperty) propIter.next();
ExtendedIterator<? extends OntProperty> eqProp = ontProperty.listEquivalentProperties();
if(eqProp.hasNext()){
while (eqProp.hasNext()) {
OntProperty property = (OntProperty) eqProp.next();
PropertyModel propModel = new PropertyModel();
propModel.setLabel(property.getLocalName());
propModel.setUri(property.getURI());
propModel.setRange(property.getRange().getLocalName());
properties.add(propModel);
}
}
...
每次我致电property.getRange()
我都会得到以下结果:http://www.w3.org/2002/07/owl#Thing。
有人帮助我吗?
答案 0 :(得分:1)
如果您提供完整但数据最少的数据,那就容易多了。在这种情况下,我已经将您的数据修改为以下内容,这是完整的,因为它是一个可加载的RDF文档,并且最小的只是它包含对象属性声明和范围公理。
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:ObjectProperty rdf:about="http://stackoverflow.com/q/24250198/1281433/aat2209_located_in">
<rdfs:range>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://stackoverflow.com/q/24250198/1281433/ArchaeologicalSite"/>
<rdf:Description rdf:about="http://stackoverflow.com/q/24250198/1281433/Building"/>
</owl:unionOf>
</owl:Class>
</rdfs:range>
</owl:ObjectProperty>
</rdf:RDF>
以下代码加载它并显示属性的范围:
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
public class RangeExample {
public static void main(String[] args) {
OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_RULE_MEM_INF );
model.read( "..../data.owl" );
OntProperty locatedIn = model.getOntProperty( "http://stackoverflow.com/q/24250198/1281433/aat2209_located_in" );
ExtendedIterator<? extends OntResource> ranges = locatedIn.listRange();
while ( ranges.hasNext() ) {
System.out.println( ranges.next() );
}
}
}
我的输出是
http://www.w3.org/2002/07/owl#Thing
-3e020093:146a7247e66:-7ffb
http://www.w3.org/2000/01/rdf-schema#Resource
owl:Thing和rdfs:资源就在那里,因为只要你有x located_in y
,就可以确定y
是猫头鹰:Thing和rdfs:Resource,因为located_in
是对象属性。另一个-3e020093:146a7247e66:-7ffb
是RDF空白节点的标识符,它是OWL联合类表达式。
基于以下评论,听起来需要更多的讨论。
我获得了相同的结果,但我将获得ArchaeologicalSite和Building。
您询问了您声明的特定对象属性的范围。在OWL中,属性p的范围是任何D类,使得“ if p(x,y),然后 D(y)”。也就是说,在RDF术语中,如果属性p具有D作为范围,那么只要存在三x p y
,那么您还可以推断三元组y rdf:type D
。这是规则:
x p y p rdfs:range D
-----------------------
y rdf:type D
您要问的范围是工会类。您班级的规则实例如下:
x located_in y located_in rdfs:range (ArchaeologicalSite OR Building)
-------------------------------------------------------------------------
y rdf:type (ArchaeologicalSite OR Building)
推断
y rdf:type ArchaeologicalSite
或
y rdf:type Building
因为这比x located_in y
中的信息更多。打个比方,请考虑这个例子:
从那些,我可以推断x是汤或沙拉,但我不能推断出哪一个。因此,“汤或沙拉”是一系列有开胃菜的,但既不是汤也不是沙拉。