Closed Demirrr closed 2 months ago
@nkaralis and @alkidbaci any idea ?
Can you please post the query that is passed to the parseQuery
function?
parseQuery
takes the following as input
∃ date.{1885 ; Nunen \/ Nuenen , Netherlands }
SELECT
DISTINCT ?x WHERE {
?x <https://www.gennarovessio.com/artgraph-schema#date> ?s_1 .
FILTER ( ?s_1 IN (
"1885 ; Nunen \/ Nuenen , Netherlands "^^<http://www.w3.org/2001/XMLSchema#string>
) )
}
Is ∃ date.{1885 ; Nunen \/ Nuenen , Netherlands }
part of the query?
Also, FILTER ( ?s_1 IN ( "1885 ; Nunen \/ Nuenen , Netherlands "^^<http://www.w3.org/2001/XMLSchema#string> ) )
is problematic. "1885 ; Nunen \/ Nuenen , Netherlands "^^<http://www.w3.org/2001/XMLSchema#string>
is this supposed to be three different values? \/
is not a valid combination of characters.
Is ∃ date.{1885 ; Nunen \/ Nuenen , Netherlands } part of the query?
yes
1885 ; Nunen \/ Nuenen , Netherlands
represents a single object in a triple that is a literal.
Below, there are examples of such literals. Please take a look at
artgraph:date "1885 ; Nunen \\/ Nuenen , Netherlands " ;
artgraph:date "1890 ; Auvers-sur-oise , France " ;
artgraph:date "1886 ; Paris , France " ;
<https://www.gennarovessio.com/artgraph-resources#21582>
a artgraph:Artwork ;
artgraph:about <https://www.gennarovessio.com/artgraph-resources#2746>, <https://www.gennarovessio.com/artgraph-resources#2893> ;
artgraph:createdBy <https://www.gennarovessio.com/artgraph-resources#1099> ;
artgraph:date "1885 ; Nunen \\/ Nuenen , Netherlands " ;
artgraph:hasGenre <https://www.gennarovessio.com/artgraph-resources#9> ;
artgraph:hasStyle <https://www.gennarovessio.com/artgraph-resources#43> ;
artgraph:image_url "https://uploads8.wikiart.org/images/vincent-van-gogh/gordina-de-groot-head-1885(1).jpg" ;
artgraph:madeOf <https://www.gennarovessio.com/artgraph-resources#2563>, <https://www.gennarovessio.com/artgraph-resources#2567> ;
artgraph:name "vincent-van-gogh_gordina-de-groot-head-1885.jpg" ;
artgraph:title "Gordina de Groot, Head" .
<https://www.gennarovessio.com/artgraph-resources#21580>
a artgraph:Artwork ;
artgraph:about <https://www.gennarovessio.com/artgraph-resources#2746>, <https://www.gennarovessio.com/artgraph-resources#2893> ;
artgraph:createdBy <https://www.gennarovessio.com/artgraph-resources#1099> ;
artgraph:date "1890 ; Auvers-sur-oise , France " ;
artgraph:hasGenre <https://www.gennarovessio.com/artgraph-resources#14> ;
artgraph:hasStyle <https://www.gennarovessio.com/artgraph-resources#39> ;
artgraph:image_url "https://uploads0.wikiart.org/images/vincent-van-gogh/girl-with-straw-hat-sitting-in-the-wheat-1890(1).jpg" ;
artgraph:locatedIn <https://www.gennarovessio.com/artgraph-resources#134348>, <https://www.gennarovessio.com/artgraph-resources#134879>, <https://www.gennarovessio.com/artgraph-resources#135043> ;
artgraph:name "vincent-van-gogh_girl-with-straw-hat-sitting-in-the-wheat-1890.jpg" ;
artgraph:title "Girl with Straw Hat, Sitting in the Wheat" .
<https://www.gennarovessio.com/artgraph-resources#21581>
a artgraph:Artwork ;
artgraph:about <https://www.gennarovessio.com/artgraph-resources#2723>, <https://www.gennarovessio.com/artgraph-resources#2769> ;
artgraph:createdBy <https://www.gennarovessio.com/artgraph-resources#1099> ;
artgraph:date "1886 ; Paris , France " ;
artgraph:hasGenre <https://www.gennarovessio.com/artgraph-resources#10> ;
artgraph:hasStyle <https://www.gennarovessio.com/artgraph-resources#43> ;
artgraph:image_url "https://uploads3.wikiart.org/images/vincent-van-gogh/glass-with-roses-1886(1).jpg" ;
artgraph:locatedIn <https://www.gennarovessio.com/artgraph-resources#134348>, <https://www.gennarovessio.com/artgraph-resources#134879>, <https://www.gennarovessio.com/artgraph-resources#135043> ;
artgraph:madeOf <https://www.gennarovessio.com/artgraph-resources#2551>, <https://www.gennarovessio.com/artgraph-resources#2552> ;
artgraph:name "vincent-van-gogh_glass-with-roses-1886.jpg" ;
artgraph:title "Glass with Roses" .
We need to use repr()
.
from owlapy.class_expression import OWLDataOneOf
from owlapy.owl_property import OWLDataProperty
from owlapy.owl_literal import OWLLiteral
from owlapy import owl_expression_to_sparql
from owlapy.class_expression import OWLDataSomeValuesFrom
p={'type': 'uri', 'value': 'https://www.gennarovessio.com/artgraph-schema#date'}
o={'type': 'literal', 'value': "1885 ; Nunen \\/ Nuenen , Netherlands ", 'datatype': 'http://www.w3.org/2001/XMLSchema#string'}
data_prob=OWLDataProperty(p["value"])
x = OWLDataSomeValuesFrom(property=OWLDataProperty(p["value"]),
filler=OWLDataOneOf(OWLLiteral(value=repr(o["value"]))))
print(owl_expression_to_sparql(expression=x))
x = OWLDataSomeValuesFrom(property=OWLDataProperty(p["value"]),
filler=OWLDataOneOf(OWLLiteral(value=o["value"])))
print(owl_expression_to_sparql(expression=x))
Do you have any suggestion in covering these cases without asking user to use repr()
? @nkaralis @alkidbaci ?
This issue is tackled in ontolearn!
We can update the rendering of the OWLLiteral as shown below:
149 # owlapy/converter.py
150 @render.register
151 def _(self, lit: OWLLiteral):
152 if lit.is_string():
153 return f'{repr(lit.get_literal())}^^<{lit.get_datatype().to_string_id()}>'
154 return f'"{lit.get_literal()}"^^<{lit.get_datatype().to_string_id()}>'
but the problem is that the query will look like this as it does in Demir's code also:
SELECT
DISTINCT ?x WHERE {
?x <https://www.gennarovessio.com/artgraph-schema#date> ?s_1 .
FILTER ( ?s_1 IN (
'1885 ; Nunen \\/ Nuenen , Netherlands '^^<http://www.w3.org/2001/XMLSchema#string>
) )
}
if you notice there is a double backslash \\/
and not \/
as the string is supposed to look like.
Im not sure if SPARQL need such escaping characters right?
I have suggested this workaround in the ontolearn
Here is the traceback
owlapy 1.1.1