Hi there
I have two general questions regarding the generality/applicability of Owlready2: 1- how limiting are the limitations to supported SPARQL constructs in Owlready2? 2- is Owlready2 meant specifically for biomedical ontologies and ultimately not really usable on any ontology? I describe below the background to these questions. Any feedback would be appreciated. Thank you in advance. Kind Regards, Jos Lehmann - Background - I have been trying to get started with Owlready2 (v0.33), specifically from a dataiku python recipe. Following the instructions on [1] and [2] I have managed to load & run very limited SPARQL-queries on the pizza ontology [3] as well as on an a private ontology loaded on dataiku. I have not managed, though, to run what to me look like very simple queries, e.g. select all individuals of a given class in the ontology, I often get a "Lexing Error". Before delving any deeper into Owlready2, I would to make sure that the Owl/Python interface is not limited wrt Owl 2 or SPARQL or other important Semantic Web standards [1] https://pypi.org/project/Owlready2/ [2] https://owlready2.readthedocs.io/en/latest/sparql.html#performing-sparql-queries [3] http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl |
Administrator
|
Hi,
Owlready2 can use any ontology in any domain. It includes some advanced functionalties that were inspired by the problem I encountered with biomedical ontologies. However, these functionalities might still be useful outside medicine, and they are optional -- you can not use them at all if they do not match your need. Owlready2 has been largely used outside the medical domains, e.g. in particle physics, material science, aeronotics, home automation, etc. Regarding SPARQL, Owlready has two options: RDFlib (fair support of SPARQL but slow) and the Owlready native engine (much faster but still very new and does not support some complex query). But options are able to perform simple queries such as listing the individuals of a class (without or with subclasses). The native SPARQL engine translates the query in SQL, and thus allows performances similar to SQL. It supports: * SELECT, INSERT and DELETE queries * UNION, OPTIONAL, FILTER, BIND, FILTER EXISTS, FILTER NOT EXISTS * SELECT sub queries * All SPARQL functions and aggregation functions * Blank nodes notations with square bracket, e.g. '[ a XXX]' * Parameters in queries (i.e. '??') * Property path expressions, e.g. 'a/rdfs:subClassOf*', excepted those listed below But the following are not supported: * SERVICE (Federated queries) * GRAPH, FROM, FROM NAMED keywords * VALUES in SELECT queries * MINUS * Property path expressions with parentheses of the following forms: - nested repeats, e.g. (a/p*)* - sequence nested inside a repeat, e.g. (p1/p2)* - negative property set nested inside a repeat, e.g. (!(p1 | p2))* i.e. repeats cannot contain other repeats, sequences and negative property sets. Could you send me an example of SPARQL query that raises a Lexing error, please ? Jiba |
This post was updated on .
Hi Jiba
thank you for the Info. I will have to work further with owlready to understand its pros/cons ratio when used on concrete examples. Presently I gather that owlready is able to support more expressive versions of OWL than, for instance, a repo like GraphDB. Regarding the Lexing error, it has to do with the prefix onto. . Please note that I initially was querying an .owl file and could produce the Lexing error. After reloading the environment in dataiku, the .owl file could no longer be parsed (see A below). I am not sure why. So, I loaded an .rdf version of the ontology instead. I got the Lexing error when using prefix onto. (see B-1-) and no error when using PREFIX (see B-2-). Please let me know if I'm doing something wrong. Kind regards, Jos A onto_path = [] onto_path.append("/home/dataiku/dss/managed_folders/JOSLIFE/Do1ezEMa") onto = get_ontology("/home/dataiku/dss/managed_folders/JOSLIFE/Do1ezEMa/trend-ontologyV3--.owl") onto.load() OwlReadyOntologyParsingError: OWL/XML parsing error in file /home/dataiku/dss/managed_folders/JOSLIFE/Do1ezEMa/trend-ontologyV3--.owl, line 92, column 37. B onto_path = [] onto_path.append("/home/dataiku/dss/managed_folders/JOSLIFE/Do1ezEMa") onto = get_ontology("/home/dataiku/dss/managed_folders/JOSLIFE/Do1ezEMa/trend-ontologyV3--N.rdf") onto.load() -1- list(default_world.sparql(""" SELECT ?label WHERE { onto.Turnover rdfs:label ?label . } """)) --------------------------------------------------------------------------- LexingError Traceback (most recent call last) <ipython-input-12-3870767bbedf> in <module> 4 SELECT ?label 5 WHERE { onto.Turnover rdfs:label ?label . } ----> 6 """)) ~/dss/code-envs/python/py3-IE-update-1/lib/python3.6/site-packages/owlready2/namespace.py in sparql(self, sparql, params, error_on_undefined_entities) 510 def sparql(self, sparql, params = (), error_on_undefined_entities = True): 511 import owlready2.sparql.main --> 512 query = self._prepare_sparql(sparql, error_on_undefined_entities) 513 return query.execute(params) 514 ~/dss/code-envs/python/py3-IE-update-1/lib/python3.6/site-packages/owlready2/namespace.py in _prepare_sparql(self, sparql, error_on_undefined_entities) 516 def _prepare_sparql(self, sparql, error_on_undefined_entities): 517 import owlready2.sparql.main --> 518 return owlready2.sparql.main.Translator(self, error_on_undefined_entities).parse(sparql) 519 520 def prepare_sparql(self, sparql, error_on_undefined_entities = True): # lru_cache does not handle optional args ~/dss/code-envs/python/py3-IE-update-1/lib/python3.6/site-packages/owlready2/sparql/main.py in parse(self, sparql) 72 self.escape_mark += "รง" 73 CURRENT_TRANSLATOR.set(self) ---> 74 self.main_query = PARSER.parse(LEXER.lex(sparql)) 75 76 sql = "" ~/dss/code-envs/python/py3-IE-update-1/lib/python3.6/site-packages/owlready2/rply.py in parse(self, tokenizer, state) 422 if lookaheadstack: lookahead = lookaheadstack.pop() 423 else: --> 424 try: lookahead = next(tokenizer) 425 except StopIteration: lookahead = None 426 ~/dss/code-envs/python/py3-IE-update-1/lib/python3.6/site-packages/owlready2/rply.py in next(self) 347 return token 348 else: --> 349 raise LexingError('Lexing error near "%s..."!' % self.s[self.idx : self.idx + 15], self.idx) 350 351 __next__ = next LexingError: ('Lexing error near "onto.Turnover r..."!', 49) -2- list(default_world.sparql(""" PREFIX trdo: <https://www..../trend-ontology#> SELECT ?label WHERE { trdo:Turnover rdfs:label ?label . } """)) [['Turnover']] |
Administrator
|
Hi,
In -1-, the prefix is not right. The prefix should always be followed by ":", not by ".". In addition, the automatic prefix created by Owlready are based on the name of the ontology (here, https://www..../trend-ontology => the prefix will be "trend-ontology:"), not on the name of the python variable that contains the ontology object (here, onto). You should try: list(default_world.sparql(""" SELECT ?label WHERE { trend-ontology:Turnover rdfs:label ?label . } """)) Regarding the parsing of the OWL file, I can look at this problem if you send me the file by email (or at list the problematic part of it). Jiba |
Hi there
OK thanks. I will try that. I was using onto. as standard Owlready2 prefix as done in the pizza example used in [1] KR, Jos [1] https://pypi.org/project/Owlready2/ |
Free forum by Nabble | Edit this page |