Search() and SPARQL query for properties

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Search() and SPARQL query for properties

Hamico
Hi guys,
I have a problem with the queries. I write an extract of my code:

property = onto.search(list(buy.get_relations()))
print(property)

I have the error AttributeError: ‘_SearchList’ object has no attribute ‘target’

I want to extract the singular data from tuple and to compare with other data. It is possible to do this with the method .search or it’s necessary to use SPARQL query? Is there a documentation on SPARQL query? Can you write some examples of queries to do this with .search and/or SPARQL query? I have an individual client, a class car and an object property buy. I want to extract dinamically the relations between a particular client and all the cars and to take the car of interesting to print. Is possible that with the instruments of .search and SPARQL query dinamically or is necessary to use a method like split() in Java to separate every singular element? I hope there is a solution dinamically for that and that my question can be useful for the other members of this forum.

Thanks to all for to be in this wonderful community.
Thank you for your time.
Best regards,
Your affectionate friend Hamico

Reply | Threaded
Open this post in threaded view
|

Re: Search() and SPARQL query for properties

Jiba
Administrator
Hi,

.search() expects keyword arguments or the form "property_name = value", for example :

clients = onto.search(have_buy = car)

if you don't know the property name at runtime, you can use **:

prop_name = "have_buy"
clients = onto.search(** {prop_name : car})

If you want to search for the property between objects, .search() is not appropriate for that. SPARQL can do it, or a loop over the various properties (iterate on properties, and verify if they have at least one car).

Best regards,
Jiba