Hi everyone,
I done some research and didn't found any solution egarding my situation. Here it is: I have two ontologies CloudOntology.owl and IaaS.owl, the thing is that CloudOntology has a dependency on IaaS.owl and I can't figure out how to load both ontologies on a World or any other valid solution that also sync the reasoner. I have both ontologies owl files locally on my computer I'm posting the code for better explanation: from owlready2 import * from pprint import pprint class SparqlQuery: def __init__(self): onto_path.append("/home/gilberto/PycharmProjects/cloud_ontology/Ontology/") onto = get_ontology("CloudOntology.owl") onto2 = get_ontology("IaaS.owl") onto.imported_ontologies.append(onto2) # Here I was trying using a World, I always get an error trying to load CloudOntology.owl # But I always succeed when loading IaaS.owl alone # my_world = World() # my_world.get_ontology("CloudOntology.owl").load() # Here I get the following: # This is my onto: get_ontology("CloudOntology.owl#") # This is my ontology imports: [get_ontology("IaaS.owl#")] print("This is my onto: ", onto) print("This is my ontology imports: ", onto.imported_ontologies) # Here is where I got stuck, it seems I can't sync my reasoner unless it is a World # sync_reasoner(onto) # reasoner is started and synchronized here # self.graph = onto.as_rdflib_graph() # Just a method for querying the ontology def search(self): # Search query is given here # Base URL of your ontology has to be given here query = """ PREFIX ab: <http://www.owl-ontologies.com/CloudOntology.owl> SELECT ?s ?p ?o WHERE { ?s ?p ?o . } """ print(query) # query is being run resultsList = self.graph.query(query) # creating json object response = [] for item in resultsList: # print("\t\tItem >\t\t\t\t\t\t\t\t", item) s = str(item['s'].toPython()) s = re.sub(r'.*#', "", s) p = str(item['p'].toPython()) p = re.sub(r'.*#', "", p) o = str(item['o'].toPython()) o = re.sub(r'.*#', "", o) response.append({'s': s, 'p': p, 'o': o}) return response runQuery = SparqlQuery() # response = runQuery.search() # pprint(response) # just to show the output I also searched alot on the documentation, but I didn't found out how to solve this. I'm sure its just me not knowing how to do the code properly, but can anyone help me with this? Thanks in advance. |
Administrator
|
Hi,
By default, Owlready uses a single world called "default_world". This should be fine for your application. You can just load ontologies with get_ontology(...).load(), and call the reasoner with sync_reasoner() (without parameter, it uses default_world). Jiba |
Hy Jiba,
first, thanks for the really quick answer, I'm gonna try this. Regards. |
I changed my code to this:
from owlready2 import * from pprint import pprint class SparqlQuery: def __init__(self): onto_path.append("/home/gilberto/PycharmProjects/cloud_ontology/Ontology/") default_world.get_ontology("CloudOntology.owl").load() sync_reasoner() # reasoner is started and synchronized here self.graph = default_world.as_rdflib_graph() Now I was getting this error message: * Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation * Owlready2 * Running HermiT... java -Xmx2000M -cp /home/gilberto/PycharmProjects/cloud_ontology/venv/lib/python3.6/site-packages/owlready2/hermit:/home/gilberto/PycharmProjects/cloud_ontology/venv/lib/python3.6/site-packages/owlready2/hermit/HermiT.jar org.semanticweb.HermiT.cli.CommandLine -c -O -D -I file:////tmp/tmpfm1v8ow_ Traceback (most recent call last): File "/home/gilberto/PycharmProjects/cloud_ontology/sparql_query.py", line 46, in <module> runQuery = SparqlQuery() File "/home/gilberto/PycharmProjects/cloud_ontology/sparql_query.py", line 12, in __init__ sync_reasoner() # reasoner is started and synchronized here File "/home/gilberto/PycharmProjects/cloud_ontology/venv/lib/python3.6/site-packages/owlready2/reasoning.py", line 126, in sync_reasoner_hermit output = subprocess.check_output(command, stderr = subprocess.STDOUT) File "/usr/lib/python3.6/subprocess.py", line 336, in check_output **kwargs).stdout File "/usr/lib/python3.6/subprocess.py", line 418, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['java', '-Xmx2000M', '-cp', '/home/gilberto/PycharmProjects/cloud_ontology/venv/lib/python3.6/site-packages/owlready2/hermit:/home/gilberto/PycharmProjects/cloud_ontology/venv/lib/python3.6/site-packages/owlready2/hermit/HermiT.jar', 'org.semanticweb.HermiT.cli.CommandLine', '-c', '-O', '-D', '-I', 'file:////tmp/tmpfm1v8ow_']' returned non-zero exit status 1. Process finished with exit code 1 I ran the debug tool in Pycharm setting a flag when I sync the reasoner, in the stdout got the following exception: 'Exception in thread "main" org.semanticweb.owlapi.model.OWLRuntimeException: org.coode.owlapi.rdfxml.parser.TranslatedUnloadedImportException: org.semanticweb.owlapi.model.UnloadableImportException: Could not load imported ontology: <http://www.owl-ontologies.com/IaaS.owl> Cause: Server returned HTTP response code: 429 for URL: http://www.owl-ontologies.com/IaaS.owl\norg.semanticweb.owlapi.model.UnloadableImportException: Could not load imported ontology: <http://www.owl-ontologies.com/IaaS.owl> Cause: Server returned HTTP response code: 429 for URL: http://www.owl-ontologies.com/IaaS.owl [...] So I figured that it was trying to fetch the IaaS ontology from the url http://www.owl-ontologies.com/IaaS.owl so I headed to my ontology, and saw the line that was causing my troubles: <owl:Ontology rdf:about=""> <owl:imports rdf:resource="http://www.owl-ontologies.com/IaaS.owl"/> </owl:Ontology> I have the IaaS.owl locally in my computer in the path that I setted on the onto_path, any advice on how can I load this dependency locally? I don't want it to look for it in the web. And thanks again for the help. |
I've managed to do that by substituting the import line by the local path as follows:
before: <owl:Ontology rdf:about=""> <owl:imports rdf:resource="http://www.owl-ontologies.com/IaaS.owl"/> </owl:Ontology> after: <owl:Ontology rdf:about=""> <owl:imports rdf:resource="file:///home/gilberto/PycharmProjects/cloud_ontology/Ontology/IaaS.owl"/> </owl:Ontology> And again, thanks for the help. |
Administrator
|
In reply to this post by Gilberto Lobo
Hi,
I think you need to load the second ontology in Python before calling the reasonner, using : default_world.get_ontology("http://www.owl-ontologies.com/IaaS.ow").load() Jiba |
This post was updated on .
Hi,
I tried to do so, I added the code to Python as you said: class SparqlQuery: def __init__(self): onto_path.append("/home/gilberto/PycharmProjects/cloud_ontology/Ontology/") default_world.get_ontology("CloudOntology.owl").load() default_world.get_ontology("http://www.owl-ontologies.com/IaaS.owl").load() pprint(default_world.search(iri = "*")) sync_reasoner() # reasoner is started and synchronized here self.graph = default_world.as_rdflib_graph() Got a diferent log message, a huge one, here's some lines of it: * Owlready2 * Running HermiT... java -Xmx2000M -cp /home/gilberto/PycharmProjects/cloud_ontology/venv/lib/python3.6/site-packages/owlready2/hermit:/home/gilberto/PycharmProjects/cloud_ontology/venv/lib/python3.6/site-packages/owlready2/hermit/HermiT.jar org.semanticweb.HermiT.cli.CommandLine -c -O -D -I file:////tmp/tmptbmsmwvp * Owlready2 * HermiT took 2.448326587677002 seconds * Owlready * Reparenting CloudOntology.Ecision: {CloudOntology.CloudServiceName} => {CloudOntology.BusinessPerformanceManagement, CloudOntology.Financial_Risk_Management, CloudOntology.SaaSProvider, CloudOntology.CloudServiceName, CloudOntology.BusinessPlan} * Owlready * Reparenting CloudOntology.Fundingroadmap: {CloudOntology.CloudServiceName} => {CloudOntology.Analysis_Statement_Report, IaaS.US_Canada, CloudOntology.SaaSProvider, CloudOntology.CloudServiceName, CloudOntology.Collaboration, CloudOntology.BusinessPlan, CloudOntology.Accounting} * Owlready * Reparenting CloudOntology.Iplanner: {CloudOntology.CloudServiceName} => {CloudOntology.Budget_Management, CloudOntology.Project_Management, CloudOntology.Financial_Risk_Management, CloudOntology.SaaSProvider, CloudOntology.CloudServiceName, CloudOntology.Collaboration, IaaS.Europe_and_UK, CloudOntology.Document_Management, CloudOntology.BusinessPlan} * Owlready * Reparenting CloudOntology.EGrid_OS: {CloudOntology.CloudServiceName} => {CloudOntology.EDI-_Electronic_Data_Interchange, CloudOntology.VMI_-_Vendor_Managed_Inventori, CloudOntology.ERP-Enterprise_Recource_Plannig, CloudOntology.Inventory_Management, CloudOntology.CloudServiceName, CloudOntology.SaaSProvider, CloudOntology.SCM_-_Supply_Chain_Management} * Owlready * Reparenting CloudOntology.Zoho: {CloudOntology.CloudServiceName} => {CloudOntology.BI-Management, CloudOntology.Email_Archiving, CloudOntology.ASP, CloudOntology.JSP, CloudOntology.Collaboration, CloudOntology.Invoice_Sales_Ordering, CloudOntology.Billing, CloudOntology.Personal_Notes, IaaS.HTTP_REST, CloudOntology.Sales_Automation, CloudOntology.Address_Books, CloudOntology.Project_Portfolio_Management, CloudOntology.Sales_Management, CloudOntology.BI_Reports, CloudOntology.SaaSProvider, CloudOntology.CRM-Custommer_Relationship_Management, CloudOntology.Contact_Management, CloudOntology.PHP, CloudOntology.Task_Management_Assignment, CloudOntology.Analysis_Statement_Report, CloudOntology.VMI_-_Vendor_Managed_Inventori, CloudOntology.Support_Services, CloudOntology.CloudServiceName, CloudOntology.Productivity_Suite, CloudOntology.Calander, CloudOntology.Appointments_and_Scheduling, CloudOntology.PaaSProvider, CloudOntology.LeadManagement, IaaS.US_Canada, CloudOntology.Project_Management, CloudOntology.Help_Desk, CloudOntology.Time_Tracking} * Owlready * Reparenting CloudOntology.WorkXpressCRM: {CloudOntology.CloudServiceName} => {CloudOntology.Facility_Management, CloudOntology.Production_Scheduling, CloudOntology.Asset_Management, CloudOntology.LeadManagement, CloudOntology.VMI_-_Vendor_Managed_Inventori, CloudOntology.ERP-Enterprise_Recource_Plannig, CloudOntology.Inventory_Management, CloudOntology.CloudServiceName, CloudOntology.SaaSProvider, CloudOntology.IT_Management, CloudOntology.CRM-Custommer_Relationship_Management, CloudOntology.Application_LifeCycle_Management, CloudOntology.WorkForce_Management, CloudOntology.Accounting} * Owlready * Reparenting CloudOntology.Deposco: {CloudOntology.CloudServiceName} => {CloudOntology.Facility_Management, IaaS.US_Canada, CloudOntology.VMI_-_Vendor_Managed_Inventori, CloudOntology.WMS-_Warehouse_Management_System, CloudOntology.ERP-Enterprise_Recource_Plannig, CloudOntology.BI_Reports, CloudOntology.Inventory_Management, CloudOntology.CloudServiceName, CloudOntology.SaaSProvider, CloudOntology.SCM_-_Supply_Chain_Management} * Owlready * Reparenting CloudOntology.Xtertain: {CloudOntology.CloudServiceName} => {CloudOntology.Facility_Management, CloudOntology.VMI_-_Vendor_Managed_Inventori, CloudOntology.ERP-Enterprise_Recource_Plannig, CloudOntology.Inventory_Management, CloudOntology.CloudServiceName, CloudOntology.SaaSProvider} * Owlready * Reparenting CloudOntology.Purchase: {CloudOntology.Financial} => {CloudOntology.AvailableServices_Inthe_Cloud, CloudOntology.Financial} And goes on... Does that mean that the dependencies where loaded? Thanks again. |
Administrator
|
Hi,
It seems that everything is Ok now. The long message is the inferrence done by the reasoner. For example, the following: * Owlready * Reparenting CloudOntology.Purchase: {CloudOntology.Financial} => {CloudOntology.AvailableServices_Inthe_Cloud, CloudOntology.Financial} Means that the class CloudOntology.Purchase was a child of CloudOntology.Financial, and is now a child of both CloudOntology.AvailableServices_Inthe_Cloud and CloudOntology.Financial. You can remove these messages by calling the reasoner as follows: sync_reasoner(debug = 0) Jiba |
Thanks again Jiba, for all the help and promptness.
|
Free forum by Nabble | Edit this page |