Search code examples
pythoneclipsejenaontologyapache-jena

How to create domain ontology lexicon by getting all the classes name attribute relations and save it in the lists


I am new to the ontology and semantic analysis. currently, I have one public ontology source which was from BBC website. the source is in " .ttl " format. I was also to load the source in Jena by using eclipse. However, i was a little lost when i see the code.

Here is some example:

<http://www.bbc.co.uk/ontologies/bbc/Mobile>
      a       <http://www.bbc.co.uk/ontologies/bbc/Platform> ;
      <http://www.w3.org/2000/01/rdf-schema#comment>
              "Represents the web documents designed for a smaller, mobile screen."@en-gb ;
      <http://www.w3.org/2000/01/rdf-schema#isDefinedBy>
              <http://www.bbc.co.uk/ontologies/bbc> ;
      <http://www.w3.org/2000/01/rdf-schema#label>
              "Mobile"@en-gb .

<http://www.bbc.co.uk/ontologies/bbc/primaryContent>
      a       <http://www.w3.org/2002/07/owl#ObjectProperty> ;
      <http://www.w3.org/2000/01/rdf-schema#comment>
              "Represents the fact that a web document has as primary content the creative work (e.g., a news story about Tom Daley is the primary content of a webpage)."@en-gb ;
      <http://www.w3.org/2000/01/rdf-schema#domain>
              <http://www.bbc.co.uk/ontologies/bbc/WebDocument> ;
      <http://www.w3.org/2000/01/rdf-schema#isDefinedBy>
              <http://www.bbc.co.uk/ontologies/bbc> ;
      <http://www.w3.org/2000/01/rdf-schema#label>
              "primaryContent"@en-gb ;
      <http://www.w3.org/2000/01/rdf-schema#range>
              <http://www.bbc.co.uk/ontologies/creativework/CreativeWork> ;
      <http://www.w3.org/2002/07/owl#inverseOf>
              <http://www.bbc.co.uk/ontologies/bbc/primaryContentOf> .

So how can I getting all the classes name attribute relations and save it in the lists?? Is it possible to do it in Python?? As I am not sure hoe rdflib in python can be use


Solution

  • for subj, pred, obj in g:
        subname = subj.split("/")[-1]  
    

    This way you can get the name of the subject.