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

Nepomuk scripting

Tags: None
(comma "," separated)
erikiiofph7
Registered Member
Posts
11
Karma
0
OS

Nepomuk scripting

Fri Feb 11, 2011 6:42 pm
How do I write scripts that perform nepomuk searches?

Is there any command line tool for performing nepomuk searches?
Or do I need to write some C/java/perl code using a nepomuk library?

What I wanna do is to make "best of" directories of my photos for each of ten tags. So all photos that has both a certain tag and 5 stars should be copied to a "best of" directory. This should be done for all ten tags, therefore I want to write a script to update the "best of" directories...
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Nepomuk scripting

Fri Feb 11, 2011 9:57 pm
Assuming you have the appropriate nepomuksearch:/ url's for your search terms, then you can use kioclient to perform the copying.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
erikiiofph7
Registered Member
Posts
11
Karma
0
OS

Re: Nepomuk scripting

Sat Feb 12, 2011 12:01 pm
I'm not familiar to neither kioclient nor nepomuksearch url's.

As a start, I tried to list the search result of a nepomuk search for items having the tag called my_tag using this command:
Code: Select all
kioclient cat nepomuksearch:/hastag=my_tag

But that didn't work, the only output I had was this:
Code: Select all
erik@brum:~> kioclient cat nepomuksearch:/hastag=my_tag
<unknown program name>(7165)/ ClientApp::doIt: Creating ClientApp
erik@brum:~>

What does this mean?
Is it a syntax error in the nepomuk search URL? (edit: The nepomuk search URL works fine for searches in Dolphin)
Or can't it find any tag called my_tag?
Or am I using kioclient in the wrong way?
User avatar
dpalacio
Registered Member
Posts
240
Karma
2
OS

Re: Nepomuk scripting

Sat Feb 12, 2011 3:04 pm
Are you sure nepomuksearch:/ is not Dolphin specific? I copy the nepomuk URL into konqueror and it cannot find the KIO slave.


connect(post, SIGNAL(readSignature()), qapp, SLOT(quit()));
erikiiofph7
Registered Member
Posts
11
Karma
0
OS

Re: Nepomuk scripting

Sat Feb 12, 2011 3:17 pm
I have no idea, I'm new to nepomuk searches.

I also tried this nepomuk search:
Code: Select all
nepomuksearch:/?query=+hasTag:my_tag

This search also worked in Dolphin, but gave similar output with kioclient:

Code: Select all
erik@brum:~> kioclient cat nepomuksearch:/?query=+hasTag:my_tag
<unknown program name>(7980)/ ClientApp::doIt: Creating ClientApp
erik@brum:~>
User avatar
dpalacio
Registered Member
Posts
240
Karma
2
OS

Re: Nepomuk scripting

Sat Feb 12, 2011 4:58 pm
I think using kioclient here is wrong because it only retrieves readable data. A search result is not readable in the sense kioclient requires.

These queries should fail:
kioclient cat file:///
kioclient cat nepomuksearch:/?query=+hasTag:my_tag

But, this works, tested on Konsole:
1. Type 'kioclient cat ' in Konsole (notice the space at the end)
2. From Dolphin's search result, drag and drop a file to the terminal. This should put a long nepomuk url.
3. Press Enter. Now the file should be print in the terminal.


How to do scripting? Ruby or Python bindings
Example in Ruby that should get you a starting point:
Code: Select all
require 'korundum4'
require 'nepomuk'
tag = Nepomuk::Tag.new( 'test' )
resource = Nepomuk::Resource.new( '/tmp/test' )
resource.add_tag tag


connect(post, SIGNAL(readSignature()), qapp, SLOT(quit()));
erikiiofph7
Registered Member
Posts
11
Karma
0
OS

Re: Nepomuk scripting

Sat Feb 12, 2011 6:18 pm
dpalacio wrote:But, this works, tested on Konsole:
1. Type 'kioclient cat ' in Konsole (notice the space at the end)
2. From Dolphin's search result, drag and drop a file to the terminal. This should put a long nepomuk url.
3. Press Enter. Now the file should be print in the terminal.

Well, this do print the file, but when using drag-and-drop I get the path to that specific file. Then the point of doing the search is gone...
erikiiofph7
Registered Member
Posts
11
Karma
0
OS

Re: Nepomuk scripting

Sat Feb 12, 2011 6:34 pm
Actually, I had some success. Before, I tried to use 'kioclient cat', which I thought would list the matching files. But it's not listing, its printing the content assuming it's text. So I changed it to 'kioclient copy' to copy the matching files, which is what I want really.

I did like this:
Code: Select all
erik@brum:~> kioclient copy nepomuksearch:/?query=+hasTag:my_tag /tmp/best_of/
<unknown program name>(9649)/ ClientApp::doIt: Creating ClientApp
A KUiServerJobTracker instance contains 1 stalled jobs
erik@brum:~>

I still get almost the same output, but this time it actually copies the files!

Now I only have to figure out how to search for items with a certain rating...
erikiiofph7
Registered Member
Posts
11
Karma
0
OS

Re: Nepomuk scripting  Topic is solved

Sun Feb 13, 2011 4:34 pm
Now I have figured it out. I found some info on the search string syntax on this page: http://techbase.kde.org/Development/Tutorials/Metadata/Nepomuk/QueryService

With that info I figured out the search string I wanted for finding all images that are both tagged with my_tag and rated with at least 4 stars:
Code: Select all
nepomuksearch:/?query=+hasTag:my_tag and rating>=8


Then the search string has to be escaped so that ' ' becomes '%20' and '>' becomes '%3E'.

So, this was my final command for copying all matching files to /tmp/best_of/:
Code: Select all
kioclient copy nepomuksearch:/?query=+hasTag:my_tag%20and%20rating%3E=8 /tmp/best_of/
User avatar
dpalacio
Registered Member
Posts
240
Karma
2
OS

Re: Nepomuk scripting

Sun Feb 13, 2011 8:01 pm
What would be nice and useful is a `kiols` program. I wrote one in Ruby but it always crashes. Ideally it should be written in C++ and included in KDE runtime.


connect(post, SIGNAL(readSignature()), qapp, SLOT(quit()));


Bookmarks



Who is online

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