我正在編寫一個代碼生成器,用於從此處定義的架構http://schema.rdfs.org/all.ttl生成實體(Java語言中的POJO)。我正在使用Jena來解析ttl文件並檢索我需要生成的元數據。使用Jena解析schema.org ttl/owl文件
Jena成功解析文件,但由於某種原因,它沒有列出給定實體的所有屬性,例如Person。我不知道我是否做錯了什麼,使用了錯誤的API等。下面是重現場景中的代碼示例:
public class PersonParser {
public static void main(String[] args) {
OntModel model = ModelFactory.createOntologyModel();
URL url = Thread.currentThread().getContextClassLoader().getResource("schema_org.ttl");
model.read(url.toString(), "TURTLE");
OntClass ontclass = model.getOntClass("http://schema.org/Person");
Iterator<OntProperty> props = ontclass.listDeclaredProperties();
while (props.hasNext()) {
OntProperty p = props.next();
System.out.println("p:" + p.getLocalName());
}
}
}
基本上,我在尋找才叫人,並試圖一類列出所有的屬性和我所得到的是:
p:alternateName
p:deathDate
p:alumniOf
p:sameAs
p:url
p:additionalName
p:homeLocation
p:description
p:nationality
p:sibling
p:follows
p:siblings
p:colleagues
p:memberOf
p:knows
p:name
p:gender
p:birthDate
p:children
p:familyName
p:jobTitle
p:workLocation
p:parents
p:affiliation
p:givenName
p:honorificPrefix
p:parent
p:colleague
p:additionalType
p:honorificSuffix
p:image
p:worksFor
p:relatedTo
p:spouse
p:performerIn
但是,如果你看一下http://schema.org/Person,它有一堆,它沒有列表(例如address
)屬性。的schema:address
在http://schema.rdfs.org/all.ttl的聲明是:
schema:address a rdf:Property;
rdfs:label "Address"@en;
rdfs:comment "Physical address of the item."@en;
rdfs:domain [ a owl:Class; owl:unionOf (schema:Person schema:Place schema:Organization) ];
rdfs:range schema:PostalAddress;
rdfs:isDefinedBy <http://schema.org/Person>;
rdfs:isDefinedBy <http://schema.org/Place>;
rdfs:isDefinedBy <http://schema.org/Organization>;
.
有沒有人碰到這個?我應該使用不同的耶拿接口來解析模式嗎?
然後我明白的是,某些類的listDeclaredProperties(也獲得了超類的屬性),它不同於OWL中熟悉的語義(一個類是子類屬性的一個域)。 但是,除了迭代屬性以外,是否有某種方式可以以OWL語義方式獲取屬性,並且在運行推理器時詢問它是否具有域? –