Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
Created May 16, 2017 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambdamusic/fdcb35eeb03f1d6f5b5e5d704e2d8f1a to your computer and use it in GitHub Desktop.
Save lambdamusic/fdcb35eeb03f1d6f5b5e5d704e2d8f1a to your computer and use it in GitHub Desktop.
ontospy example: extracting labels and descriptions
In [1]: import ontospy
In [2]: o = ontospy.Ontospy("foaf.rdf")
In [4]: c = o.classes[0]
In [5]: c
Out[5]: <Class *http://www.w3.org/2000/10/swap/pim/contact#Person*>
In [6]: c.bestLabel()
Out[6]: rdflib.term.Literal(u'Person')
In [7]: for c in o.classes:
...: print c, c.bestLabel(), c.bestDescription()
...:
<Class *http://www.w3.org/2000/10/swap/pim/contact#Person*> Person
<Class *http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing*> Spatial Thing
<Class *http://xmlns.com/foaf/0.1/Agent*> Agent An agent (eg. person, group, software or physical artifact).
<Class *http://xmlns.com/foaf/0.1/Document*> Document A document.
<Class *http://xmlns.com/foaf/0.1/Group*> Group A class of Agents.
<Class *http://xmlns.com/foaf/0.1/Image*> Image An image.
<Class *http://xmlns.com/foaf/0.1/LabelProperty*> Label Property A foaf:LabelProperty is any RDF property with texual values that serve as labels.
<Class *http://xmlns.com/foaf/0.1/OnlineAccount*> Online Account An online account.
<Class *http://xmlns.com/foaf/0.1/OnlineChatAccount*> Online Chat Account An online chat account.
<Class *http://xmlns.com/foaf/0.1/OnlineEcommerceAccount*> Online E-commerce Account An online e-commerce account.
<Class *http://xmlns.com/foaf/0.1/OnlineGamingAccount*> Online Gaming Account An online gaming account.
<Class *http://xmlns.com/foaf/0.1/Organization*> Organization An organization.
<Class *http://xmlns.com/foaf/0.1/Person*> Person A person.
<Class *http://xmlns.com/foaf/0.1/PersonalProfileDocument*> PersonalProfileDocument A personal profile RDF document.
<Class *http://xmlns.com/foaf/0.1/Project*> Project A project (a collective endeavour of some kind).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment