Question

I have the follow ontology:

<!-- 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>

I'm trying to extract Labels, comments and about from classes, properties definitions. I'm using RDFlib to parse the file. I want to have the output:

(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 

My initial code:

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

I really don't know how to continue! Does anyone can help me?

Était-ce utile?

La solution

It can be solved using sparql. The same problem is answered in Why my query doesn't work using RDFlib which is same problem.

The code could be like this:

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 }
}

Anyway, since I've posted this answer, I studied some RDFlib codes and sparql. The latter might be applicable for the most cases.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top