How to add instances from dbpedia to ontology - insert

I am trying to add all countries to my ontology from dbpedia. However, it says that no countries were added. I am using GraphDB for this. I saw another post here that had the format to what I should use, but I still couldn't make it work. Can someone help me? Here is my query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://www.dbpedia.org/ontology>
PREFIX dbr: <http://www.dbpedia.org/resource>
INSERT
{ ?s ?p ?o }
WHERE
{ SERVICE <http://dbpedia.org/sparql>
{
?s rdf:type dbo:Country.
?s ?p ?o.
}
}

Related

Amazon Neptune Full Text Search - specify fields

So SPARQL documentation contains examples how to specify multiple fields to search for:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
SERVICE neptune-fts:search {
neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
neptune-fts:config neptune-fts:queryType 'query_string' .
neptune-fts:config neptune-fts:query 'mikael~ OR rondelli' .
neptune-fts:config neptune-fts:field foaf:name .
neptune-fts:config neptune-fts:field foaf:surname .
neptune-fts:config neptune-fts:return ?res .
}
}
I'm trying to do the same thing, but in Gremlin:
g.withSideEffect('Neptune#fts.endpoint', '...')
.V().has(['name', 'company'], 'Neptune#fts term*')
This obviously doesn't work. Now I could use wildcard like this:
g.withSideEffect('Neptune#fts.endpoint', '...')
.V().has('*', 'Neptune#fts term*')
But now I'm matching all the fields, and it fails because our index has too many. (There's a limit of 1,024 I think.)
Any idea how to specify a list of fields to search through in a Gremlin query?
Meanwhile I found a workaround, which works but is not very clean:
You can set your query to use query_string format like this:
.withSideEffect("Neptune#fts.queryType", "query_string")
It will be less forgiving for syntax, but it means you can search for fields inside the query:
field1:foo AND field2:bar
Now with Neptune it's not so simple, because your field names aren't just field1, field2, but they are formatted like this:
predicates: {
field1: {
value: "..."
},
field2: {
value: "..."
}
}
That's fine, you just need to modify the query:
predicates.field1.value:foo AND predicates.field2.value:bar
And here's how I do "make sure that some of the fields match term":
predicates.field1.value:<term> OR predicates.field2.value:<term>

SPARQL query select top object property in Protege

I currently make SPARQL queries for android API about finding the right dog breeds, based on hypoallergenic, purpose, cost, and energy level.
Here is the class hierarchy screenshot :
Here is the data property hierarchy :
Here is object property hierarchy :
Here are individuals :
the result I want is the dog breeds (beagle, basenji, dachshund wirehaired, saluki, dachshund miniature, whippet, as seen as individual in picture 4), which hasPurpose is Hound.
I try this query but it didn't show what i wanted.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?individual ?hasPurpose
WHERE {
?individual rdf:rdfs hasPurpose:Hound
}

SPARQL Query Computational Complexity

I have a list of SPARQL queries with various patterns (e.g., select, union, join). I want to calculate their time complexity by using big O notation (e.g., O(n), O(nlogn)). Please let me know how to do that. I have more than 3000,0000,000 triples in my RDF graph.
Followings are some example query queries
Query 1:
select ?o where { <http://example.com/person_info/242622027> vocab:info_gender ?o}
Query 2:
select ?o ?k where {
{
?s vocab:person_info_pid '242622027'^^xsd:decimal.
?s vocab:person_info_homeloc ?o
}
UNION
{
?i vocab:activities_pid '242622027'^^xsd:decimal.
?i vocab:activities_purpose ?k
}
}
Query3:
select (count(*) as ?no) where{
?s vocab:outputparttwo_iteration '0'^^xsd:decimal
}
SPARQL itself is PSPACE-complete. You can probably only come up with the best case complexity for any given query. The real-world complexity will depend on the implementation of the database to some degree.

Unable to query French DBpedia with an accent in resource IRI (Modèle)

On the French DBpedia endpoing, I am trying to search all pages using a particular infobox. This is my query:
SELECT ?person WHERE {
?person <http://fr.dbpedia.org/property/wikiPageUsesTemplate> <http://fr.dbpedia.org/page/ModèleInfobox_Politicien>
} LIMIT 100
It finds no result, but there are many of them, e.g.,
http://fr.dbpedia.org/page/Fran%C3%A7ois_Hollande
I suspect that the problem is due to the accent in the resource. I have also tried with an url-encoded accent:
SELECT ?person WHERE {
?person <http://fr.dbpedia.org/property/wikiPageUsesTemplate> <http://fr.dbpedia.org/page/Mod%C3%A8leInfobox_Politicien>
} LIMIT 100
The URI has a colon in it between Modèle and Infobox. You query should be
select ?person where {
?person prop-fr:wikiPageUsesTemplate <http://fr.dbpedia.org/resource/Modèle:Infobox_Politicien>
}
limit 100
SPARQL results

ElasticSearch "Match" with FullText Matches

I'm working with ElasticSearch.
When I do this query:
{query: "blackberry -q10"}
I get exactly what I want (all results which have reference to BlackBerry but not Q10).
However, I want to restrict the fields which are searched to just the "title" field. Eg, the _source documents have titles, body, tags, etc. and I only want to search the title. The ElasticSearch "Match" seems right for me...
{query: {match: {title: "blackberry -q10"}}}
While this succeeds in only searching the title, it still returns results with have Q10 in the title, unlike the search above.
I'm looking at the match documentation but can't seem to figure it out.
Thanks!
The Match query doesn't use negation syntax like that. E.g you can't use a "minus" to negate a term. It will be parsed as a hyphen by the default search analyzer.
I would use a filtered query in this case. You could add the negation in a query...but a filter will be much faster.
{
"filtered":{
"query":{
"match":{
"title":"blackberry"
}
},
"filter":{
"bool":{
"must_not":{
"term":{
"title":"q10"
}
}
}
}
}
}
Note, you may need to change the term filter, depending on how you analyzed the field at index time.
EDIT:
Based on your comment below, if you really want to keep the ability to do negations "inline", you would use the field query (a more specific version of query_string, which would also work). This query uses Lucene syntax, which allows inline negation
{
"field" : {
"title" : "blackberry -q10"
}
}
The reason query_string and it's derivatives are not recommended is because it is easy to shoot yourself in the foot. Or rather, it's easy for your users to shoot your server in the face. Query_string demands proper syntax and will simply die if the users enter it incorrectly. It also allows your users to make some horrible inefficient queries, usually through wildcards
You want to match all the titles that have "blackberry" AND do not have have q10, not all the titles that have "blackberry" OR do not have q10.
The default boolean operator for a match is (in most cases) OR. Try adding an "operator": "and" clause to your query instead.

Resources