This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Very Simple Nepomuk Query Task with C++ or Python API

Tags: None
(comma "," separated)
johannesf
Registered Member
Posts
2
Karma
0
Hi, I'm trying to create a simple Query with whatever (C++/Python) to interact with an PHP-Script. I know that Nepomuk is pretty good for handling complex Tag-Relations and their are a lot of examples out there. But I couldn't find something simple (just like "grep xxxx yyyy"). In general, what I want to do is, to ask Nepomuk(Akonadi) for parts of filename or Filecontent and list the Files with the absolute Path.

This Script [1] is able to complete this task, but just return the File-Names, not the full path. Someone knows, how to change the script, to get the
path?

Are their any C++-Examples which can do this task? I found a lot with all possible combinations of tag/time.... I'm not comfort in writing SPARQL, but if it's necassary, how can I write a "list all file which contains name "YYYY""-query?


Thanks for your work.


[1] https://projects.kde.org/projects/kde/kdeexamples/repository/revisions/1931b66c973bb0009f9b70a931e800505fc997b8/entry/bindings/python/nepomuk/nepomuk_tag_query_example.py
User avatar
Ignacio Serantes
Registered Member
Posts
453
Karma
1
OS
This is a query to locate all files with pdf extension using a regular expression ".pdf$".
Code: Select all
SELECT DISTINCT ?url
WHERE {
      ?r nie:url ?url . FILTER(REGEX(bif:lower(?url), ".pdf$"^^xsd:string, 'i')) .
}


To print a resource nie:url ontology you can use next code:
Code: Select all
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from PyKDE4.soprano import Soprano
from PyKDE4.nepomuk import Nepomuk

resource = Nepomuk.Resource(QUrl("nepomuk:/res/<the rest of the uri>"))
print(resource.property(Nepomuk.Vocabulary.NIE.url()).toUrl().toString().toUtf8())
resource = None


Ignacio Serantes, proud to be a member of KDE forums since 2008-Nov.
johannesf
Registered Member
Posts
2
Karma
0
Thanks a lot Ignacio - this was exactly what works for me:

Code: Select all
resource.property(Nepomuk.Vocabulary.NIE.url()).toUrl().toString().toUtf8()


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Google [Bot], Sogou [Bot]