how to search for strings with different language

2019-08-05 00:58发布

问题:

I need to search items in two graphs with the same string, but different language codes ("xx"@en and "xx"@eng - from wordnet). obviously "xx"@en is not equal to "xx"@eng.

it can be done with (prefix nlp suitably defined):

select * where {
   ?a nlp:lemma ?as . 
   ?b rdfs:label ?bs . 
   filter (str(?as)=str(?bs)) . 
     # more code using ?a and ?b
}

However, this query takes too long and is wasteful. It should be possible to do something like:

?a nlp:lemma ?s . 
?b rdfs:label ?s .

but i cannot see how - short of manually change all @eng in the wordnet triples to @en - which i would rather not do.

any solution? thank you!

回答1:

You could cut you search space down by filtering only for en and eng, but the only way to compare the string portion of a language-labeled string is to convert them to a string.

I.e. the following could be more efficient if there are language-labeled strings other than en and eng:

select * where {
   ?a nlp:lemma ?as . 
   ?b rdfs:label ?bs . 
   filter (lang(?as) = "en" || lang(?as) = "eng")
   filter (str(?as)=str(?bs)) . 
     # more code using ?a and ?b
}


标签: sparql