Wikidata / Wikidata-Toolkit

Java library to interact with Wikibase
https://www.mediawiki.org/wiki/Wikidata_Toolkit
Apache License 2.0
372 stars 100 forks source link

Getting entities by SPARQL query #362

Open WolfgangFahl opened 6 years ago

WolfgangFahl commented 6 years ago

It would be great to be able to get entities with a SPARQL query e.g.

SELECT ?station WHERE {
  # P954 = Internationale Bahnhofsnummer IBNR
  ?station wdt:P954 ?ibnr.
  # filter to show only german stations
  FILTER regex(?ibnr,"^80","i")
}

which should give a list of railway stations

Tpt commented 6 years ago

It is indeed something that would be great to be added to this library. What you could do for now is use an RDF/SPARQL library like RDF4J [1] and its SPARQLRepository class or Jena.

[1] http://rdf4j.org/ [2] https://jena.apache.org/documentation/rdfconnection/

wetneb commented 6 years ago

I have used Jena for that and it works well. It lets you create SPARQL queries programmatically too.

luisenriqueramos1977 commented 5 years ago

Hi, about this question, I am working in the following:

Adding company1 with some information to a private wikidata, wich I am currently doing, and later I should be able to search for the company1, and update any information. In this part, I made a very simple search by entity name, which last too long. I though in implementing an sparql query, but it seems not being implemented yet in java API.

I know jena, and rdf4j, my question is how implementing that?, as I understand all the wikidata "data" should be in rdf format to proceed with it, or I am wrong and there is another way to interact with the wikidata itself?.

Luis Ramos

akuckartz commented 5 years ago

I am not sure what this issue is about. Does this help?https://m.wikidata.org/wiki/Special:MyLanguage/Wikidata:SPARQL_query_service/Wikidata_Query_Help

luisenriqueramos1977 commented 5 years ago

Hi Andrea, thanks for your quick answer,

for my understanding the information you provide is for users, I mean that is not for developers, it explains about rdf dump, but my interest is searching, and updating the graph directly from the wikidata, and I am not sure if that is feasible.

Luis

Tanish-Gupta commented 4 years ago

Hi, Can you please give more insights about the problem? Like what is the above query fetching right now? Thank you

WolfgangFahl commented 4 years ago

The query is just an example. If you are interested in what it does you might want to try it using the wikiDataQuery service. I have added the label service which will display the label of each result - this is a non -standard RDF feature and therefore the example itself does not use it.

For more examples you might want to go thru my SPARQL tutorial

Tanish-Gupta commented 4 years ago

I went through the SPARQL tutorial, it was quite well explained. I would like to know what exactly the issue is? What I can understand is that in the "try it" query (given in the above comment) the labels have been found using Service "wikibase:label" which is defined by us and is not a standard RDF feature. And we need to find entities (like labels) using standard queries? Can you please correct me if you are expecting something else?

Thank you

WolfgangFahl commented 4 years ago

This issue is about adding an API to run the queries within the WikiData Toolkit. So any "standard" RDF Query against WikiData should be runnable and return a result in a decent simple format. Currently this is only possible in combination with other libraries and e.g. not tested out of the box.

Tanish-Gupta commented 4 years ago

Hi, Where can I find the triples stored, on which the WikiData runs its queries? Also, what are the endpoints of that server in order to make an RDF connection?

luisenriqueramos1977 commented 4 years ago

Tanish,

In this tutorial it is explained how to configure blazegraph:

https://heardlibrary.github.io/digital-scholarship/lod/install/

Perhaps it helps you to answer your questions.

Luis

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Virenfrei. www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

El dom., 24 may. 2020 a las 10:15, Tanish-Gupta (notifications@github.com) escribió:

Hi, Where can I find the triples stored, on which the WikiData runs its queries? Also, what are the endpoints of that server in order to make an RDF connection?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Wikidata/Wikidata-Toolkit/issues/362#issuecomment-633196239, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALS7GAHGVKWWE6NKVPAXDRDRTDJQ7ANCNFSM4E4O2SMQ .

Tanish-Gupta commented 4 years ago

Hi, I am still unclear about the exact requirement in this issue. Can you please describe it once again in detail?

What I can figure out is :-

  1. This query is working on Wikidata Query Service platform

SELECT ?station WHERE { ?station wdt:P954 ?ibnr. FILTER regex(?ibnr,"^80","i") }

  1. So is "try it" query running. But, this also gives the labels associated with the station names which are extracted using Service keyword (These two are the ones you mentioned in the comments. )

So, what exactly is the aim of the API? since the standard SPARQL queries are also working on that Wikidata Query Service platform. If possible also mention the files I should go through for the same.

Thank you for the help

WolfgangFahl commented 4 years ago

@Tanish-Gupta you might want to ask your question in an environment that is more suitable for a question and answer format like stackoverflow.com - I'll happily answer there.

62mkv commented 4 years ago

So, are there any plans to expose SPARQL-client functionality as part of Wikidata-Toolkit? Would be huge added value, I think.

Currently I am planning to write a script that will add forms to lexemes, by first finding a lexeme by it's lemma. Couldn't find way to do it via WikibaseDataFetcher. With SPARQL it would be

SELECT ?lexeme ?lemma WHERE {
  ?lexeme dct:language wd:Q9072;
   wikibase:lemma ?lemma.
  FILTER (STR(?lemma)="aprill")
}
wetneb commented 4 years ago

@62mkv I am not aware of anyone working on this. It would be a nice thing to have indeed!