0

我有以下本体:

<!-- http://purl.org/ontology/bibo/Article -->
<owl:Class rdf:about="Article">
    <rdfs:label xml:lang="en">Article</rdfs:label>
    <rdfs:subClassOf rdf:resource="Document"/>
    <rdfs:isDefinedBy rdf:datatype="&xsd;anyURI"
        >http://purl.org/ontology/bibo/</rdfs:isDefinedBy>
    <ns:term_status>stable</ns:term_status>
    <rdfs:comment xml:lang="en"
        >A written composition in prose, usually nonfiction, on a specific topic, forming an independent part of a book or other publication, as a newspaper or magazine.</rdfs:comment>
</owl:Class>

<!-- http://purl.org/ontology/bibo/AudioDocument -->

<owl:Class rdf:about="AudioDocument">
    <rdfs:label xml:lang="en">audio document</rdfs:label>
    <rdfs:subClassOf rdf:resource="Document"/>
    <rdfs:isDefinedBy rdf:datatype="&xsd;anyURI"
        >http://purl.org/ontology/bibo/</rdfs:isDefinedBy>
    <ns:term_status>stable</ns:term_status>
    <rdfs:comment xml:lang="en"
        >An audio document; aka record.</rdfs:comment>
</owl:Class>

<!-- http://purl.org/NET/c4dm/event.owl#place -->

<owl:ObjectProperty rdf:about="&event;place">
    <skos:scopeNote xml:lang="en"
        >Used to relate an event such as a conference to the geographical place where it happens, for example Paris.</skos:scopeNote>
</owl:ObjectProperty>

<!-- http://purl.org/dc/terms/date -->

<owl:DatatypeProperty rdf:about="&terms;date">
    <skos:scopeNote xml:lang="en"
        >Use to link a bibliographic item to the date of an event. Check dcterms:created and other for proper specializations for this property</skos:scopeNote>
</owl:DatatypeProperty>

我正在尝试从类、属性定义中提取标签、评论和关于。我正在使用 RDFlib 来解析文件。我想要输出:

(about) Article
(label) Article
(comment) written composition in prose, usually nonfiction, on a specific topic, forming an independent part of a book or other

(about) AudioDocument
(label) Audio Document
(comment) An audio document; aka record.

(about) place
(scopeNote) Used to relate an event such as a conference to the geographical place where it happens, for example Paris.

(about) date
(scopeNote) use to link a bibliographic item to the date of an event. check dcterms:created and other for proper specializations 

我的初始代码:

for s, p, o in graph:
    if type(s) == rdflib.term.URIRef:
            print 'Subject = ',s 
            print ' '
            print 'Property = ',p 
            print ' '
            print 'Object = ',o 
            print ' '

我真的不知道怎么继续!有人可以帮助我吗?

4

1 回答 1

0

可以使用 sparql 解决。为什么我的查询不能使用 RDFlib解决了同样的问题,这是同样的问题。

代码可能是这样的:

PREFIX ns: <http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT DISTINCT ?varClass ?varSubClass ?varSubClassComment ?varProperty ?varPropComment
FROM <http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf>
WHERE {
  VALUES ?propertyType { owl:ObjectProperty owl:DatatypeProperty }

  ?varClass rdf:type owl:Class .
  ?varProperty rdf:type ?propertyType ;
               rdfs:domain ?varClass .
  OPTIONAL{ ?varProperty rdfs:comment ?varPropComment }
  OPTIONAL{ ?varSubClass rdfs:subClassOf ?varClass ;
                         rdfs:comment ?varSubClassComment }
}

无论如何,自从我发布了这个答案后,我研究了一些 RDFlib 代码和 sparql。后者可能适用于大多数情况。

于 2013-11-18T20:07:13.707 回答