Menu
  • HOME
  • TAGS

SPARQL why are there both DELETE and WHERE conditions?

Tag: rdf,sparql,triplestore,sparul

Recently I was deleting some data according to a matching pattern ?s a :answers and I notices that I could only get the deletion to correctly proceed if I had both condition blocks as the same:

PREFIX :      <http://localhost:2020/vocab/> 
DELETE {
    ?s a :answers
}
WHERE {
    ?s a :answers
}
# returns all the correct data

and if the delete block is more generalized, nothing is returned:

PREFIX :      <http://localhost:2020/vocab/>
DELETE {
    ?s ?p ?o
}
WHERE {
    ?s a :answers
}
# returns 0 rows

What is the purpose of having two different sets of conditions (the stuff between curly braces: {...} )? and which one actually selects the data to be deleted?

Best How To :

Because what you delete may not be what you match with WHERE.

There is a special form for the first case:

DELETE WHERE { ?s a :answers }

In the second, ?p and ?o are not bound. Try:

DELETE {
    ?s ?p ?o
}
WHERE {
    ?s a :answers .
    ?s ?p ?o .
}

How to get all nouns in a certain language from Wiktionary using SPARQL

sparql,wiktionary

First of all, you want to select all term senses that are nouns. As you can see in the query result of the example query, this information is captured by the terms:hasPoS relation. So, to specifically query all nouns, we could do this: PREFIX terms: <http://wiktionary.dbpedia.org/terms/> SELECT ?term WHERE {...

Reasoning and datatypes of Literals

rdf,owl,reasoning,turtle,stardog

According to the docs: RDF parsing in Stardog is strict: it requires typed RDF literals to match their explicit datatypes, URIs to be well-formed, etc. In some cases, strict parsing isn’t ideal—it may be disabled using the --strict-parsing=FALSE. However, even with strict parsing disabled, Stardog’s RDF parser may encounter parse...

Virtuoso 37000 Error SP030

sparql,semantics,semantic-web,virtuoso

The query you've shown us might not be the same as the query you're actually running. First, the fact that the error message says "line 1" makes me wonder whether you've actually got the query run all onto one line. That can make it easy to get typo problems. When...

SPARQL subquery in DBpedia

sparql,dbpedia

If you write the query: SELECT distinct * { ?nomePT owl:sameAs category:Algorithms. } You will get all links that are owl:sameAs your resource category:Algorithms. However, you are already limiting the scope of the triple. So if you ask for: SELECT distinct ?nomePT { ?nomePT owl:sameAs category:Algorithms. ?nomePT rdfs:label ?label }...

setting soft limit for 4store client

sparql,4store

By default 4store gives a soft limit of about 1000. You have a couple of options to tweak/disable search breadth: If using 4s-query you can override the setting with --soft-limit e.g. 4s-query --soft-limit 5000 demo 'SELECT ... etc.'. Setting it to -1 completely disables it. If using a 3rd party...

What is the use of @vocab in JSON-LD and what is the difference to @context?

rdf,json-ld

@vocab is used specifically to declare a default vocabulary from which all terms derive, without having to declare specific mappings for each term (as you normally do in a @context). For example, see this snippet (taken from the JSON-LD 1.0 spec): { "@context": { "@vocab": "http://schema.org/" } "@id": "http://example.org/places#BrewEats", "@type":...

MarkLogic 8 - Node.js Client API - Can I do a SPARQL Query?

node.js,sparql,marklogic

The MarkLogic node.js client API can evaluate SPARQL queries. See the jsdoc here: http://docs.marklogic.com/jsdoc/graphs.html#sparql Update: here's a full example: var marklogic = require('marklogic') var config = { /* ... */ } var db = marklogic.createDatabaseClient(config) db.graphs.sparql( 'application/sparql-results+json', 'select ?s ?p ?o\n' + 'where { ?s ?p ?o }\n' + 'limit...

Storing separately individuals and ontology in sesame store

sparql,semantic-web,sesame

It's possible to store your individuals and the ontology in separate repositories and then query over them together, yes. However, it's not a common way to handle things. A far simpler approach is that you put both datasets in the same Repository, but put each in a separate context or...

Reify triples in JSON-LD

rdf,json-ld

I'm not sure if you really want to assign "a type" to the whole triple, but as you ask for it and mention Reification, you could do something like this: [ { "@id": "http://www.example.com/id/linkFrom", "http://www.example.com/link": [ { "@id": "http://www.example.com/id/linkTo" } ] }, { "@id": "http://www.example.com/reifi/1", "@type": [ "http://www.example.com/vocab#specialLink", "http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement" ],...

multiple users accessing RDF file for read and write

apache,rdf,jena,rdfs

Have a look at the Concurrency HowTo of the Jena website. Follow relevant links for TDB/SDB transactions. According to the documentation: Locks provide critical section support for managing the interactions of multiple threads in the same JVM. Jena provides multiple-reader/single-writer concurrency support (MRSW). The pattern general is: Model model =...

Unexpected End of Stream while trying to tokenise sparql query

rdf,sparql,xml-namespaces

The problem is writing FILTER((\"http://www.w3.org/TR/rdf-schema/#\")<STR(?s)). You can't have a string that is bigger than a namespace. If you want to filter based on a namespace you need to see what the instances that you are filtering start with and then write something like: select distinct * where{ ?s ?p ?o...

How to add dot '.' in the name of individuals in Sparql?

sparql

your code is right and should work. It is possible to use dot in the individual's name. I think you should check your data property (relatedField), maybe is not clarified right....

SPARQL: selecting people by country

sparql,dbpedia

If we assume all the cities in a specific country are defined as part of that country in dbpedia, you could have a query that first looks for the people that have dbpedia:Portugal as a country and then cities within dbpedia:Portugal. SELECT DISTINCT ?person WHERE { ?person a dbpedia-owl:Person. Optional{...

Optimize SPARQL Query

sparql

A slight alternative to Joshua's query which should work on your Sesame database (which is an older version that contains a bug in property path evaluation): SELECT ?p ?p1 ?genre WHERE { ?p movies:hasRated [ movies:ratedMovie [ movies:hasGenre ?genre ]; movies:hasRating ?rating ]. ?p1 foaf:knows ?p ; movies:hasRated [ movies:ratedMovie...

How to get a single name for multiple name properties in DBPedia with SPARQL?

sparql,owl,dbpedia

You can do this using a COALESCE function: PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dbpprop: <http://dbpedia.org/property/> SELECT DISTINCT ?x (COALESCE(?dbpfn, ?dbpn, ?label) as ?name) WHERE { ?x a foaf:Person . OPTIONAL { ?x dbpprop:fullname ?dbpfn } OPTIONAL { ?x dbpprop:name ?dbpn } OPTIONAL { ?x rdfs:label ?label } }...

sparql to retreive the value of a min constraint

sparql,jena

Here is the sparql query I used following Artemis' answer SELECT ?min WHERE {?s rdfs:subClassOf ?o. ?o owl:minQualifiedCardinality ?min. FILTER(?s = :value) } And with jena, I use getLiteral("min").getFloat();...

MarkLogic 8 - What is the Preferred Way to Triplify Data

rdf,marklogic,triplestore,triples

If you do not want to keep the original documents (and enrich them with triples), but instead to store only triples, the easiest is to generate the triples. The preferred way to do this is indeed to generate the sem:triples documents yourself. The key point to take into account is...

SPARQL Group-Concat not working

rdf,sparql,jena

It's always helpful if you can show the query and the data complete and on their own, not just snippets and embedded in code. Here's some complete data that we can test with: <rdf:RDF xmlns:ns0="http://my.url.com/ontologies/mash-up#" xmlns:ns1="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <ns0:CalendarItem rdf:about="http://my.url.com/ontologies/mash-up#CalendarItem-uh0cjvnuehhvfjpgppiggmpjac"> <ns0:attendee...

Filter SELECT output by string in Spaql

filter,sparql

?tableName1 is in the subject position do it's a URI or blank node. Filter ( ?tableName1 = 'xyz') tests for a string. If you mean the URI contains the string xyz then: Filter ( contains(str(?tableName1),'xyz'))...

Compare average - SPARQL

sparql

It's very hard to answer these kinds of questions without some sample data to work with. Here's some sample data that has two users who have similar rankings on comedy, but different rankings on romance: @prefix : <urn:ex:> :a :ranks [ :genre :comedy ; :value 2 ], [ :genre :comedy...

sparql insert with where clause

curl,sparql,4store

You don't insert data { ... } where { ... } You can either insert constant data with: insert data { ... } or you can compute the data to insert with insert { ... } where { ... } It looks like that latter one is what you want...

Query multiple models within same Dataset in TDB Jena

rdf,sparql,jena,ontology,tdb

You can make the default graph the union of the named graphs: https://jena.apache.org/documentation/tdb/datasets.html or a subset of the graphs (efficiency issues at very large scale): https://jena.apache.org/documentation/tdb/dynamic_datasets.html...

SPARQL: How do I List and count each data type in an RDF dataset?

types,count,sparql

Since you've grouped by the datatype of ?o, you know that all the ?o values in a group have the same datatype. You can just sample that to get one of those values, and then take the datatype of it: select (datatype(sample(?o)) as ?datatype) (count(?o) AS ?dTypeCount) where { ?s...

Consequence of restrictions in ontology on SPARQL end results

rdf,sparql,semantics,owl,ontology

That's because you are querying the TBOX and ?p in your query translates to the bnode representing the anonymous class restriction. You are not binding to instances in the query, but the value/class used for the owl:allValuesFrom restriction. So http://purl.oclc.org/NET/ssnx/qu/dim#Temperature would be the result of your query. Had you wanted...

Can SPARQL handle blank results for specific cells?

web-scraping,sparql,scrape,dbpedia

Whenever you are looking for something that might and might not be present, you can put that part of the statement in an optional part of SPARQL query. Thus: select * where { ?game a dbpedia-owl:Game ; dbpprop:name ?name . optional{ ?game dbpedia-owl:publisher ?publisher . } } The count before...

What is the difference between a temporal and a non-temporal query

sql,database,sparql

As you don't refer to a specific document that talks about temporal queries, i can only give a pretty broad answer: There are many approaches on how to model temporally constrained facts in RDF. As RDF itself is only concerned with triples/quads (subject, predicate, object(, graph)), many simple mapping approaches...

MarkLogic 8 - SPARQL - Follow synonym chain

sparql,semantics,marklogic

To use SPARQL, you would need to represent this data as triples. Someone who knows ontologies better would come up with better IRIs, but something like (as represented inside MarkLogic): <triple> <subject>http://marklogic.com/scope#cat</subject> <predicate>http://marklogic.com/term</predicate> <object>cat</object> </triple> <triple> <subject>http://marklogic.com/scope#cat</subject> <predicate>http://marklogic.com/synonym</predicate>...

Sparql query to get all classes that are subclass of a “property class”

sparql,semantic-web,owl,protege

I need to "annotate" some classes by adding a property to them. I need to do that in order to let the view layer of my application extract the correct classes. That's actually what annotation properties, such as rdfs:label, are for. You can define your own annotation properties, and...

How to use the ASK WHERE statement with multiple conditions (sparql)

sparql,freebase

The query as you've written it is kind of odd. There's no use of the ?x variable, so you can immediately simplify it as: ASK where { {basekb:m.0109yb6 rdf:type basekb:music.release_track} UNION {basekb:m.0109yb6 rdf:type basekb:book.written_work} #-- ... UNION {basekb:m.0109yb6 rdf:type basekb:fictional_universe.fictional_character} } That's still got lots of repeated code, though. You...

RDF SPARQL query multiple types

java,rdf,sparql

{ ?object rdf:type ns0:TrainArrival ; rdf:type ns0:PrimaryInformation ; } will match having both TrainArrival and PrimaryInformation...

Count resources having a property of a certain type in SPARQL

rdf,sparql

Your data wasn't quite usable (there were no prefixes on the p1, p2, etc., resources), but after fixing that, I was able to use the following query. You were pretty close; the trick is that you need to filter(?p1 != ?p2) to ensure that you're getting different values of the...

Resources on OWL and Building Ontologies [closed]

rdf,ontology

There are some nice Protege tutorials which you can use to learn OWL and building ontologies. Here is one example which does exactly what you ask for: https://www.youtube.com/watch?v=MbauHV2-XYw Alternatively, one of the most famous examples for learning OWL concepts is the Pizza tutorial. I haven't found a video, but this...

Sparql query not showing results

rdf,sparql,jena,owl,ontology

I think you are forgetting how properties are defined in OWL. You have defined: Class: DiningRoom subClassOf: hasProperty some AbsoluteHumidity Thus, you need to write a more complicated query: PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#> PREFIX dgo: <http://www.iiitd.edu.in/~haroonr/ontologies/DGO#> SELECT distinct * WHERE { dgo:DiningRoom rdfs:subClassOf ?property . ?property owl:someValuesFrom ?y. } ...

how to read SPARQL query and pass via $http.get

angularjs,sparql

I think, you can use this answer: How do I POST urlencoded form data with $http in AngularJS? to form your request, and you supply query in the data: data: {query: "Put your SPARQL Query here"} SPARQL query is everything below "// SparQL Query" in your listing, just a multiline...

Persisting data in Jena TDB triple store

rdf,jena,ontology,triplestore,tdb

After receiving feedback and tweaking Jena, I found answers to all points as: Is Ryan correct about what he has discussed about dataset? From Joshua's comment and reading API I found that Jena framework has been improved a lot, so Ryan's explanation about datasets is not valid anymore. Does TDB...

OWL. How to express that siblings has common parent?

rdf,semantics,semantic-web,owl

Dave is father of Mary and Mary sister of Jack. I want reason that Dave have two childs Jack and Mary. If you ignore the possibility of siblings having different parents (e.g., a parent in common and a different parent), then you can do this with subproperty chains. If...

Why does STRAFTER return blank data in json binding in angular?

json,string,sparql

Is this maybe a string quote problem as you " string is terminated by the " in front of #. So try: var query = encodeURIComponent('SELECT (strafter(str(?class),"#") AS ?className) (COUNT(?s) AS ?count ) WHERE { ?s a ?class } GROUP BY ?class ORDER BY DESC(?count)'); ...

How to retrieve person names from DBPedia in different language versions?

r,sparql,dbpedia

The namespaces of dbpeida in different languages are different. Thus you need to change your namespace: SELECT *{ dbpedia-de:Veit_Dietrich ?p ?o } ...

Trying to understand “expected types” and “type.property.schema” properties in Freebase

rdf,freebase,rdfs

I'm not a freebase user, so I don't have a lot of context for the Freebase specific parts, here, but I can speak about about possible relationships to is expected type equal to rdfs:range? is type.property.schema equal to rdfs:domain? I'd interpret a description like: Definition: The expected type of the...

How to do a count and select variables in Sparql

sparql

SELECT (COUNT(*) as ?cnt) (sample(?s) as ?sample) { ?s a <http://foo.org/test> } COUNT means the query is an aggregate query so there are many ?s. SAMPLE picks one - which one is not defined. If you want all the ?s and the COUNT, you'd normally count in your application -...

SPARQL: Unresolved prefixed name: dbpprop:author

java,sparql,dbpedia

The DBpedia endpoint by defaults knows about many of the most common prefixes for the most common vocabularies. As pointed out by KBorja in the comment above these can be looked up here: http://dbpedia.org/sparql?nsdecl . So you want to add this to your prefixes: PREFIX dbpprop: <http://dbpedia.org/property/> Aside from that...

Ontologies, OWL, Sparql: Modelling that “something is not there” and performance considerations

performance,sparql,modeling,ontology,sesame

With respect to the modeling question, I'd like to offer a fourth alternative, which is, in fact, a mix of your options 1 and 2: introduce a separate class (hierarchy) for these 'excluded/missing' symptoms, diseases or treatments, and have the specific exclusions as instances: :Exclusion a owl:Class . :ExcludedSymptom rdfs:subClassOf...

URLError with SPARQLWrapper at sparql.query().convert()

python,sparql,ipython-notebook,fuseki,sparqlwrapper

If you attempt to execute some SPARQL request on your local fuseki server through a python script, you could be disturbed by some proxy problem. To resolve the problem you could use the auto-detect property of urllib. from SPARQLWrapper import SPARQLWrapper, JSON, XML #import urllib.request module. Don't forget for Python...