[Nepomuk] First problems with query API

Ignacio Serantes kde at aynoa.net
Tue Mar 1 23:05:40 CET 2011


Hi!

As Sebastian suggested I tried the search API without my dirty hack and I
finally learn how to use it. This is my first successful code:

term = Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("música",
'UTF-8')))
query = Nepomuk.Query.Query(term)
[code #1]
query.addRequestProperty(Nepomuk.Query.Query.RequestProperty(Nepomuk.Types.Property(NEO('nie#url',
True))))
query.addRequestProperty(Nepomuk.Query.Query.RequestProperty(Nepomuk.Types.Property(NEO('nao#prefLabel',
True))))
sparqlQuery = query.toSparqlQuery()
model = Nepomuk.ResourceManager.instance().mainModel()
data = model.executeQuery(sparqlQuery, Soprano.Query.QueryLanguageSparql)
... < code to display result set > ...
[code #1]


The query is slow but works and columns url and prefLabel are available.
Great!
896 results found in 7.69615888596 seconds

I have a common query I used often when I'm developing "ha ji won kim sa
rang" because result set has one row (this is equivalent to write "'ha' and
'ji' and 'won' and 'kim' and 'sa' and 'rang') and this is the result set
with a query generated by my builder nsSparqlBuilder.

file:///media/HD1.5TB-01/video/corea/doramas/Secret Garden, [FileDataObject]
1 results found in 1.21383500099 seconds.

So I wrote the next code to test the API expecting same results:

andTerm = Nepomuk.Query.AndTerm()
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ha",
'UTF-8'))))
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ji",
'UTF-8'))))
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("won",
'UTF-8'))))
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("kim",
'UTF-8'))))
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("sa",
'UTF-8'))))
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("rang",
'UTF-8'))))
query = Nepomuk.Query.Query(andTerm)
[code #1]

and this is the result set I obtained:

(iODBC Error: [OpenLink][Virtuoso iODBC Driver][Virtuoso Server]SQ200: The
memory pool size 400005656 reached the limit 400000000 bytes, try to
increase the MaxMemPoolSize ini setting)"
0 results found in 85.3466908932 seconds

Them I deleted two terms, the second and the five and there is no error but
result set is the next one:
0 results found in 600.101149082 seconds

Finally I discover that generated API queries works with two terms and fails
with more. For example, the next test is very slow but works:

andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ha",
'UTF-8'))))
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ji",
'UTF-8'))))


nepomuk:/res/c894d8fa-cb6a-4ab3-ab26-37a6abbe206e, , ha ji won
nepomuk:/res/c0642c10-6501-448c-a8ed-4992f45c232e,
file:///media/HD1.5TB-01/video/corea/doramas/Secret Garden,
2 results found in 25.7656869888 seconds

but the next one not:

andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ha",
'UTF-8'))))
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ji",
'UTF-8'))))
andTerm.addSubTerm(Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("won",
'UTF-8'))))


and result is:
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."
local socket error: QLocalSocket::SocketTimeoutError
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."
0 results found in 1201.46248913 seconds
"" Soprano: "Command timed out."
"" Soprano: "Command timed out."

In documentation there is no limit to the number of terms you can add and
even there is a constructor where you can add 6 terms. I tried it but
results are the same, the first term works but the second one not.

        term = Nepomuk.Query.AndTerm( \
            Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ha",
'UTF-8'))), \
            Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ji",
'UTF-8'))), \
            Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("won",
'UTF-8'))) \
            )

        term = Nepomuk.Query.AndTerm( \
            Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("ha",
'UTF-8'))), \
            Nepomuk.Query.LiteralTerm(Soprano.LiteralValue(unicode("won",
'UTF-8'))) \
            )

On the other side using API if external hard drive is not mounted result
sets are empty. This behavior can be disabled?

I only tried AndTerm but tomorrow I will try OrTerm if I have free time.

-- 
Cheers,
Ignacio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/nepomuk/attachments/20110301/e007c905/attachment-0001.htm 


More information about the Nepomuk mailing list