[Nepomuk] Query for resource for exactly one known file

Sebastian Trüg sebastian at trueg.de
Fri Aug 10 18:02:33 UTC 2012


well, getting one resource from the URL you can just use 
Nepomuk2::Resource like so:

Nepomuk2::Resource res(url);

and you have your resource.

res.uri()

will get you the resource URI.

On 08/10/2012 05:55 PM, Dean Perry wrote:
> Hi all, more noob questions:
>
> I'm trying to write something that will retrieve the resource for
> exactly one file for which I have the URL from a drag and drop
> operation... I'm using the Nepomuk::Query stuff because, to be honest, I
> can't make head nor tails of SPARQL yet.
>
> So for starters:
>
> - I know that I have a valid URL for a file
>
> - I know its is in the database and
>
> - using NepSAK I know that the resource has both NFO::fileName and
> NIE::url associated.
>
> I was thinking that NIE::url would be the thing to compare against:
>
> QString urlstring = url.toString();
>
> Nepomuk::Query::ComparisonTerm term (
>
> Nepomuk::Vocabulary::NIE::url(),
>
> Nepomuk::Query::LiteralTerm ( urlstring ),
>
> Nepomuk::Query::ComparisonTerm::Equal
>
> );
>
> But this doesn't return any results, even when I know for certain that
> the file has a resource with the NIE::url property that has the value
> I'm looking for. Changing 'Equal' to 'Contains' doesn't work either.
>
> Using NFO::fileName works fine, but returns several results if there's a
> duplicate in the file system:
>
> QString filename = urlstring.right ( ( urlstring.length() -
> urlstring.lastIndexOf ( '/' ) )-1 ); // yeah, ugly...
>
> Nepomuk::Query::ComparisonTerm term(
>
> Nepomuk::Vocabulary::NFO::fileName(),
>
> Nepomuk::Query::LiteralTerm(filename),
>
> Nepomuk::Query::ComparisonTerm::Contains
>
> );
>
> Using the FileQuery class does not help (but adds some constraints to
> the SPARQL).
>
> I've also tried to use just the filename and 'Contains' against
> NIE::url, and that doesn't work either.
>
> As I said, I'm pretty clueless with SPARQL, but when I take the Query
> generated SPARQL and paste into NepSAK the results are the same
> (obvious) but when I replace the nfo::fileName with nie::url it also
> doesn't work which is not very obvious to me eg:
>
> select distinct ?r , ?v1 as ?_n_f_t_m_ex_ where { ?r nie:url ?v1 .
> FILTER(bif:contains(?v1,
> "'095262r00ZB_zigbee_rf4ce_sc-ZigBee_RF4CE_Specification_public.pdf'"))
> . FILTER EXISTS { ?r a [ nao:userVisible "true"^^XMLSchema:boolean ] . }
> . } LIMIT 20
>
> I'm guessing I'm missing something obvious here...
>
> cheers,
>
> dean
>
> Oh and secondary questions:
>
> (1) the generated query has the stuff between ?r and ?v1 which seems
> extraneous and seems to return a result with HTML markup (<b></b> tags)
> that disappear if I remove them:
>
> select distinct ?r
> (bif:concat(bif:search_excerpt(bif:vector('095262r00ZB_zigbee_rf4ce_sc-ZigBee_RF4CE_Specification_public.pdf'),
> ?v1))) ....
>
> vs
>
> select distinct ?r, ?v1 ....
>
> produces
>
> <b>095262r00ZB</b> zigbee rf4ce sc ZigBee RF4CE Specification public.
>
> vs
>
> 095262r00ZB_zigbee_rf4ce_sc-ZigBee_RF4CE_Specification_public.pdf
>
> (2) is it just me or does the 'bool' parameter for
> QueryServiceClient::syncQuery always return 'false' ?
>
>
>
> _______________________________________________
> Nepomuk mailing list
> Nepomuk at kde.org
> https://mail.kde.org/mailman/listinfo/nepomuk
>


More information about the Nepomuk mailing list