i tried to update a value of a query in my DB on marmotta. I have a lot of resources like this:
<rdf:Description rdf:about="http://desktop-pqb3a65:8080/marmotta/resource/7e31bb9e-5dee-4f44-b082-9f770d465ea0">
<hasContentPath xmlns="http://www.kiwi-project.eu/kiwi/core/">D:\Software\Marmotta\marmotta-home\resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be</hasContentPath>
<about xmlns="http://schema.org/">Fondamenti di Informatica</about>
<name xmlns="http://schema.org/">Hello World!</name>
<author xmlns="http://schema.org/">EduOpen</author>
<audience xmlns="http://schema.org/">Qualsiasi</audience>
<actor xmlns="http://schema.org/">Gianni Vercelli</actor>
<description xmlns="http://schema.org/">Accenni storici sulla nascita del calcolatore</description>
<width xmlns="http://schema.org/"></width>
<height xmlns="http://schema.org/"></height>
<duration xmlns="http://schema.org/"></duration>
</rdf:Description>
I want to edit the hasContentPath field, i have a value like this:
D:\Software\Marmotta\marmotta-home\resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be
I'd like to edit and insert a value like :
resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be
Can you help me? i tried this query:
PREFIX schema: <http://schema.org/>
DELETE { ?resource <http://www.kiwi-project.eu/kiwi/core/> 'D:\Software\Marmotta\marmotta-home\resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be' }
INSERT { ?resource <http://www.kiwi-project.eu/kiwi/core/> 'resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be' }
WHERE
{ ?resource schema:name 'Hello World!'
}
Single \ in strings are for escape sequences. Unlike the linux shell, '' strings have escapes as well. \S is illegal as an escape — strictly speaking, that's a syntax error. It seems to be interpreted in some way, but it is unlikely to be the characters \ and S.
Related
I am querying a (kind of) bibliographic database and would like to find all the distinct matches of a certain regex (matching the signature of typescripts (TS) and manuscripts (MS)); i.e. I would like to return all documents that are currently in the database.
I came up with
SELECT ?document
WHERE
{
{
?documentURI a witt:MS;
rdfs:label ?document.
}
UNION
{
?documentURI a witt:TS;
rdfs:label ?document.
}
FILTER (regex(?document, "(Ms|Ts)\\-((1|2|3)\\d{2}\\w?\\d?)"))
}
(endpoint); this returns all the signatures but I would like to filter the result for the distinct regex matches, i.e. the distinct signatures up to and excluding the comma.
How can this be achieved?
Ok, I think I found a solution with strbefore:
SELECT DISTINCT ?document
WHERE
{
{
?documentURI a witt:MS;
rdfs:label ?documentFull.
}
UNION
{
?documentURI a witt:TS;
rdfs:label ?documentFull.
}
BIND (strbefore(?documentFull, ",") AS ?document)
}
Try it.
Would appreciate opinions on the query though, is this effective/good style?
I have this kind of structure
<ontology:Louvre>
<rdf:type ontology:Museum/>
<ontology:preserves rdf:Gioconda/>
<ontology:locatedIn rdf:Paris/>
<ontology:name>Louvre</ontology:name>
<ontology:Gioconda>
<rdf:type ontology:Artwork/>
<ontology:preserved rdf:Louvre/>
<ontology:author rdf:Leonardo/>
<nomeOpera>Gioconda</nomeOpera>
<rdf:Leonardo_Da_Vinci>
<rdf:type ontology:Painter"/>
<ontology:paint ontology:Gioconda"/>
<ontology:paint ontology:Ultima_cena"/>
<name>Leonardo Da Vinci</name>
...(other museum, artist and artwork)
I use "ontology" to indicate my prefix
Is it possible to recover the exclusive artists of a museum?
I found the solution.
This is the query that i'm looking for
SELECT DISTINCT * WHERE {
?museum ontology:preserves ?artwork .
?museum ontology:name "Louvre" .
?artwork ontology:author ?author.
FILTER NOT EXISTS{
?museum2 ontology:preserves ?artwork2 .
?artwork2 ontology:author ?author .
FILTER (?museum2 != ?museum)
}
}
I build this ontology in protege. I have this individual ev001 that has these types Room,hasRoom only {rm001} and rm001 has data property roomName "room 1"^^xsd:string.
Right now I have a SPARQL query that returns
Event Room RoomName
ev001 {rm001}
My question is, how to get the room name from there,
here is my query so far
SELECT ?event ?room ?roomname
WHERE { ?x owl:onProperty base:hasRoom .
?event a base:FilmScreening ;
a ?x .
?x owl:allValuesFrom ?room .
}
Any advice is appreciated, thank you very much
In general, it looks like you'd just need:
SELECT ?event ?room ?roomname
WHERE {
?event base:hasRoom ?room .
?room base:roomName ?roomname.
}
You don't need to be retrieving all the axiom stuff with owl:onProperty, etc. However, in your case, the ontology is structured a bit strangely. E.g., you have content like:
<!-- http://www.example.org/ontologies/loncon3#pi00314001 -->
<owl:NamedIndividual rdf:about="http://www.example.org/ontologies/loncon3#pi00314001">
<!-- ... -->
<rdf:type>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.example.org/ontologies/loncon3#hasRoom"/>
<owl:allValuesFrom>
<owl:Class>
<owl:oneOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.example.org/ontologies/loncon3#rm03005"/>
</owl:oneOf>
</owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</rdf:type>
<!-- ... -->
</owl:NamedIndividual>
In the Manchester syntax, that says that pi00314001 has the type:
hasRoom only { rm03005 }
Based on your question, it sounds like you expect the
pi00314001 hasRoom rm03005
is in your data, or at least inferable from it. Unfortunately, that's not what it actually means. When you say that an individual X has the type
p only D
it means it if X has any value for the property p, then that value must be an instance of D. Similarly, the content in your ontology says that if pi00314001 has a value for the property hasRoom, then that value must be from the class { rm03005 }. It doesn't say that pi00314001 actually has a value for that property, so you don't actually know whether it has rm03005 as a value for hasRoom or not.
If it's under your control, I think you'd want to add some actual object property assertions to your ontology, so that the query I mentioned above will work. Right now your ontology is telling you more about what's possible than what's actually the case.
That said, if you do want to retrieve the room from the data as it's structured now, you can follow the structure of the data and make that work too. It'd be something like:
select ?event ?roomName {
?event a [ owl:onProperty base:hasRoom ;
owl:allValuesFrom/owl:oneOf/rdf:rest*/rdf:first ?room ] .
?room base:roomName ?roomName .
}
Can any one please point me to some simple examples of semantic tagging and querying semantically tagged documents in MarkLogic?
I am fairly new in this area,so some beginner level examples will do.
When you say "semantically tagged" do you mean regular XML documents that happen to have some triples in them? The discussion and examples at http://docs.marklogic.com/guide/semantics/embedded are pretty good for that.
Start by enabling the triple index in your database. Then insert a test doc. This is just XML, but the sem:triple element represents a semantic fact.
xdmp:document-insert(
'test.xml',
<test>
<source>AP Newswire</source>
<sem:triple date="1972-02-21" confidence="100">
<sem:subject>http://example.org/news/Nixon</sem:subject>
<sem:predicate>http://example.org/wentTo</sem:predicate>
<sem:object>China</sem:object>
</sem:triple>
</test>)
Then query it. The example query is pretty complicated. To understand what's going on I'd insert variations on that sample document, using different URIs instead of just test.xml, and see how the various query terms match up. Try using just the SPARQL component, without the extra cts query. Try cts:search with no SPARQL, just the cts:query.
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
at "/MarkLogic/semantics.xqy";
sem:sparql('
SELECT ?country
WHERE {
<http://example.org/news/Nixon> <http://example.org/wentTo> ?country
}
',
(),
(),
cts:and-query((
cts:path-range-query( "//sem:triple/#confidence", ">", 80) ,
cts:path-range-query( "//sem:triple/#date", "<", xs:date("1974-01-01")),
cts:or-query((
cts:element-value-query( xs:QName("source"), "AP Newswire"),
cts:element-value-query( xs:QName("source"), "BBC"))))))
In case you are talking about enriching your content using semantic technology, that is not directly provided by MarkLogic.
You can enrich your content externally, for instance by calling a public service like the one provided by OpenCalais, and then insert the enrichments to the content before insert.
You can also build lists of lookup values, and then using cts:highlight to mark such terms within your content. That could be as simple as:
let $labels := ("MarkLogic", "StackOverflow")
return
cts:highlight($doc, cts:word-query($labels), <b>{$cts:text}</b>)
Or with a more dynamic replacement using spraql:
let $labels := map:new()
let $_ :=
for $result in sem:sparql('
PREFIX demo: <http://www.marklogic.com/ontologies/demo#>
SELECT DISTINCT ?label
WHERE {
?s a demo:person.
{
?s demo:fullName ?label
} UNION {
?s demo:initialsName ?label
} UNION {
?s demo:email ?label
}
}
')
return
map:put($labels, map:get($result, 'label'), 'person')
return
cts:highlight($doc, cts:word-query(map:keys($labels)),
let $result := sem:sparql(concat('
PREFIX demo: <http://www.marklogic.com/ontologies/demo#>
SELECT DISTINCT ?s ?p
{
?s a demo:', map:get($labels, $cts:text), ' .
?s ?p "', $cts:text, '" .
}
'))
return
if (map:contains($labels, $cts:text))
then
element { xs:QName(fn:concat("demo:", map:get($labels, $cts:text))) } {
attribute subject { map:get($result, 's') },
attribute predicate { map:get($result, 'p') },
$cts:text
}
else ()
)
HTH!
I am trying to retrieve the name of inkers of Comic books. I am trying to build an ontology. Inkers has dbpprop and I have imported rdlib and sparqlWrapper whilst I am having following error. Is there any one who understand this problem?
Abcde-MacBook-Pro:example Abcde$ python basicTest.py
WARNING:rdflib.term: does not look like a valid URI, trying to serialize this will break.
Abcde-MacBook-Pro:example Abcde$ python basicTest.py
Traceback (most recent call last):
File "basicTest.py", line 78, in <module>
g = sparql.query().convert()
File "build/bdist.macosx-10.10-intel/egg/SPARQLWrapper/Wrapper.py", line 535, in query
File "build/bdist.macosx-10.10-intel/egg/SPARQLWrapper/Wrapper.py", line 513, in _query
SPARQLWrapper.SPARQLExceptions.EndPointInternalError: EndPointInternalError: endpoint returned code 500 and response.
Response:
Virtuoso RDF01 Error Bad variable value in CONSTRUCT: "Malcolm Jones III" (tag 246 box flags 0) is not a valid subject, only object of a triple can be a literal
SPARQL query:
define sql:big-data-const 0
#output-format:application/rdf+xml
My code looks like
CONSTRUCT {
?comics ma:inked_by ?inker .
?inker rdf:type ma:Inker .
}
WHERE{
?comics rdf:type dbpedia-owl:Comics .
?comics foaf:name ?name .
OPTIONAL {?comics dbpprop:inkers ?inker}
FILTER regex(str(?name), "Batman")
}"""
I think the problem arises when you get the ?inker out. Sometime it is a URI and sometime it is a string. For example, the following are the top two outputs:
"Malcolm Jones III"
http://dbpedia.org/resource/Vince_Colletta
I think you need to change your code in a way that your inker is either a URI or a string. The following will save the URI in your ontology, if it exists. If you need a string use the ?inkername instead.
CONSTRUCT {
?comics ma:inked_by ?inker.
?inker a ma:Inker.
}
where {
?comics a dbpedia-owl:Comics.
?comics foaf:name ?name .
optional{
?comics dbpprop:inkers ?inker.
?inker foaf:name ?inkername.
}
FILTER regex(str(?name), "Batman")
}