[Nepomuk] Retrieve "linked" artwork file
Ignacio Serantes
kde at aynoa.net
Tue Oct 18 10:07:17 UTC 2011
On Tue, Oct 18, 2011 at 10:54 AM, <daitheflu at free.fr> wrote:
> Hi,
>
> Thanks Sebastian, that helped me *a lot*.
>
> I checked with NepomukShell and discovered that my artwork Resource had no
> NIE:url !
> I thought that the constructor would have automatically set it but it
> didn't, and it does not.
>
> Since the following wasn't sufficient :
>
> img = Nepomuk.Resource(coverpath, OntologiesUrls.image())
>
> I just added :
>
> img = Nepomuk.Resource(coverpath, OntologiesUrls.image())
> img.setProperty(OntologiesUrls.url(), coverpath)
>
> And that did the trick :)
> It's now working like a charm !
>
>
>
> As for your Python tool that generate ontologies, that could be very
> interesting.
> I could have write one by myself, but I was too lazy. So I just hardcoded
> the one I needed.
> If yours is not too difficult to understand and if you're OK, I could maybe
> maintain it.
>
I write one my own but is not a class is a function an its usage is:
* NOC('nie:url')*
*
*
or
*
*
*NOC('nie:url', True)*
*
*
if you want the result was a QUrl.
You need to know the ontology but few is hardcoded so function is almost
automantained.
<--------------------------->
*knownOntologies = [ \*
* ['nao', '2007/08/15'], ['ncal', '2007/04/02'], \*
* ['nco', '2007/03/22'], ['nexif', '2007/05/10'], \*
* ['nfo', '2007/03/22'], ['nid3', '2007/05/10'], \*
* ['nie', '2007/01/19'], ['nmm', '2009/02/19'], \*
* ['nmo', '2007/03/22'], ['nrl', '2007/08/15'], \*
* ['pimo', '2007/11/01'], ['tmo', '2008/05/20'] \*
* ]*
*
*
*# Nepomuk Ontology Converter.*
*def NOC(name = '', returnQUrl = False):*
* ontology, property = name.strip().split(':')*
* date = lvalue(knownOntologies, ontology, 0, 1)*
* if date != None:*
* value = 'http://www.semanticdesktop.org/ontologies/%s/%s#%s' %
(date, ontology, property)*
*
*
* else:*
* value = 'Soprano.Vocabulary.%s.%s().toString()' %
(ontology.upper(), property)*
* try:*
* value = eval(value)*
*
*
* except:*
* value = ''*
*
*
* if returnQUrl:*
* return QUrl(value)*
*
*
* else:*
* return value*
<--------------------------->
> Thanks again for your help.
>
> Cheers,
>
> --
> François
>
>
>
> ----- Mail original -----
> De: "Sebastian Trüg" <trueg at kde.org>
> À: nepomuk at kde.org
> Envoyé: Lundi 17 Octobre 2011 20:24:54
> Objet: Re: [Nepomuk] Retrieve "linked" artwork file
>
> On 10/17/2011 04:20 PM, daitheflu at free.fr wrote:
> > Hi guys,
> >
> > Me again. I'd like my application to link some file as an artwork for a
> Movie Type Resource.
> > The artwork consists in a .png file, stored in some directory (that's not
> the important point).
> >
> > Here is how I "link" the file to the artwork "property" of the Movie
> Resource (Python code, but you'll understand) :
> >
> > ***
> >
> > # self.artwork is a QPixmap containg the artwork.
> >
> > if not self.artwork.isNull():
> > # SNIP : saves the cover to `coverpath`.
> > # `coverpath` is a KUrl instance.
> >
> > # Build a Resource of type NFO:image from the saved picture :
> > img = Nepomuk.Resource(coverpath, OntologiesUrls.image())
>
> This reminds me that I have a python tool somewhere which generates
> ontology methods for python... have to look for it...
>
> > # "Links" that NFO:image Resource to the NMM:artwork property of my
> Movie Resource :
> > resource.setProperty(OntologiesUrls.artwork(), Nepomuk.Variant(img))
> >
> > ***
> >
> >
> > The problem is to get the .png file back. Here is what I tried :
> >
> >
> > ***
> >
> > # Get the Resource linked by the NMM:artwork property :
> > artwork = resource.property(OntologiesUrls.artwork())
> >
> > if artwork.isValid():
> > imgResource = artwork.toResource()
> > res.artwork = PictureLoader.load_pixmap(imgResource.toFile().url())
> >
> > ***
> >
> > The problem is that `imgResource.toFile().url()` returns an empty KUrl.
> >
> > Am I missing something ? What did I misunderstood ? How can I retrieve
> and load the linked artwork file ?
>
> it looks correct. Maybe use nepomukshell to look at the resources to
> make sure. You can use a query like "select * where { ?r nmm:artwork ?v
> . }" and then double-click on the resource.
>
> Cheers,
> Sebastian
> _______________________________________________
> Nepomuk mailing list
> Nepomuk at kde.org
> https://mail.kde.org/mailman/listinfo/nepomuk
> _______________________________________________
> Nepomuk mailing list
> Nepomuk at kde.org
> https://mail.kde.org/mailman/listinfo/nepomuk
>
--
Best wishes,
Ignacio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/nepomuk/attachments/20111018/6e1d96d1/attachment.html>
More information about the Nepomuk
mailing list