Created
March 13, 2012 17:52
-
-
Save vadimii/2030232 to your computer and use it in GitHub Desktop.
Groovy version of Pellet OWLAPI example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.semanticweb.owlapi.apibinding.OWLManager | |
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory | |
def I = { org.semanticweb.owlapi.model.IRI.create(it) } | |
def file = "http://www.mindswap.org/2004/owl/mindswappers#" | |
println "Reading file ${file}…" | |
def manager = OWLManager.createOWLOntologyManager() | |
def ontology = manager.loadOntology(I(file)) | |
def reasoner = PelletReasonerFactory.instance.createReasoner(ontology) | |
println "Done!" | |
reasoner.kb.realize() | |
reasoner.kb.printClassTree() | |
// create property and resources to query the reasoner | |
def personIRI = I("http://xmlns.com/foaf/0.1/Person") | |
def workInfoHomepageIRI = I("http://xmlns.com/foaf/0.1/workInfoHomepage") | |
def foafNameIRI = I("http://xmlns.com/foaf/0.1/name") | |
def df = manager.OWLDataFactory | |
def person = df.getOWLClass(personIRI) | |
def workHomepage = df.getOWLObjectProperty(workInfoHomepageIRI) | |
def foafName = df.getOWLDataProperty(foafNameIRI) | |
def individuals = reasoner.getInstances(person, false) | |
individuals.each { | |
// «it» contains information about the individual (and all other | |
// individuals that were inferred to be the same) | |
def e = it.representativeElement | |
// get the info about this specific individual | |
def names = reasoner.getDataPropertyValues(e, foafName) | |
def types = reasoner.getTypes(e, true) | |
def homepages = reasoner.getObjectPropertyValues(e, workHomepage) | |
// we know there is a single name for each | |
// person so we can get that value directly | |
def name = (names*.literal).first() | |
println "Name: ${name}" | |
// at least one direct type is guaranteed to exist for each individual | |
def type = (types*.representativeElement).first() | |
println "Type: ${type}" | |
// there may be zero or more homepages so check first if there are any found | |
println "Homepage: " + (homepages.empty ? "Unknown" : | |
(homepages*.representativeElement.iri).join(", ")) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reading file http://www.mindswap.org/2004/owl/mindswappers#… | |
Done! | |
owl:Thing | |
mindswap:EmailAddress - (mmahmud:umd.edu, …<bla-bla-bla>…, femke:geog.umd.edu) | |
funding:Funding | |
funding:BusinessFunding | |
funding:B2BFunding | |
funding:BusinessContract | |
funding:BusinessGrant | |
funding:Contract | |
funding:BusinessContract | |
funding:GovernmentContract | |
funding:GovernmentFunding | |
funding:GovernmentContract | |
funding:GovernmentGrant | |
funding:Grant | |
funding:BusinessGrant | |
funding:GovernmentGrant | |
funding:Organization - (mindswap:Mindswap, mindswap:Mindlab) | |
funding:Business | |
funding:Fundee | |
funding:Funder | |
mindswap:MindswapFunder | |
funding:Government | |
contact:Person | |
foaf:Person | |
mindswap:Swapper | |
mindswap:Affiliate - (mindswappers:Aaron.Mannes) | |
mindswap:Alumni - (mindswappers:Nada.Hashmi, …<bla-bla-bla>…, mindswappers:Anant.Kaushiva) | |
mindswap:Faculty - (mindswappers:Jim.Hendler) | |
mindswap:Staff | |
mindswap:Programmer - (mindswappers:Ron.Alford, mindswappers:Kendall.Clark, mindswappers:Mike.Grove, mindswappers:Daniel.Krech, mindswappers:Amy.Alford) | |
mindswap:Researcher - (mindswappers:Bijan.Parsia, mindswappers:David_Wood, mindswappers:Ugur_Kuter, mindswappers:Jennifer.Golbeck) | |
mindswap:Student | |
mindswap:GraduateStudent - (mindswappers:Naiwen.Lin, …<bla-bla-bla>…, mindswappers:Vladimir_Kolovski) | |
mindswap:UndergraduateStudent - (mindswappers:Jordan.Katz, mindswappers:Chris.Testa) | |
mindswap:Visitor - (mindswappers:Andrew.Schain, mindswappers:Chris.Shenton) | |
…<bla-bla-bla>… | |
mindswap:GraduateStudent - (mindswappers:Naiwen.Lin, mindswappers:Christian.Halaschek, mindswappers:Aditya.Kalyanpur, mindswappers:Debbie.Heisler, mindswappers:Evren.Sirin, mindswappers:Dave.Wang, mindswappers:Hamid_Haidarian-Shahri, mindswappers:Bin.Zhao, mindswappers:Vladimir_Kolovski) | |
mindswap:UndergraduateStudent - (mindswappers:Jordan.Katz, mindswappers:Chris.Testa) | |
mindswap:Visitor - (mindswappers:Andrew.Schain, mindswappers:Chris.Shenton) | |
wordnet:Project | |
foaf:Project | |
Name: Aaron Mannes | |
Type: <http://www.mindswap.org/2003/owl/mindswap#Affiliate> | |
Homepage: Unknown | |
Name: Jennifer Golbeck | |
Type: <http://www.mindswap.org/2003/owl/mindswap#Researcher> | |
Homepage: http://www.mindswap.org/~golbeck/ | |
…<bla-bla-bla>… | |
Name: Matt Westhoff | |
Type: <http://www.mindswap.org/2003/owl/mindswap#Alumni> | |
Homepage: Unknown | |
Name: Nada Hashmi | |
Type: <http://www.mindswap.org/2003/owl/mindswap#Alumni> | |
Homepage: http://www.mindswap.org/~nada/ | |
Name: David Wood | |
Type: <http://www.mindswap.org/2003/owl/mindswap#Researcher> | |
Homepage: http://www.mindswap.org/~dwood/ | |
Name: Ron Alford | |
Type: <http://www.mindswap.org/2003/owl/mindswap#Programmer> | |
Homepage: http://www.mindswap.org/~ronwalf/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment