Virtuoso Dump graph - graph

Hello I have a probably simple problem but I am not able to find it anywhere in docs.
I use this code in Virtuoso Interactive SQL:
SPARQL clear graph <http://product-open-data.org/temp>;
SPARQL clear graph <http://linked.opendata.cz/resource/dataset/product-open-data.org/2014-01-01>;
DB.DBA.TTLP ('
#prefix rr: <http://www.w3.org/ns/r2rml#> .
#prefix foaf: <http://xmlns.com/foaf/0.1/> .
#prefix gr: <http://purl.org/goodrelations/v1#> .
#prefix s: <http://schema.org/> .
#prefix pod: <http://linked.opendata.cz/ontology/product-open-data.org#>
<#TriplesMapBrand>
a rr:TriplesMap;
rr:logicalTable [
rr:tableSchema "POD";
rr:tableOwner "DBA";
rr:tableName "BRAND"
];
rr:subjectMap
[
rr:template "http://linked.opendata.cz/resource/brand/{BSIN}";
rr:class gr:Brand;
rr:graph <http://linked.opendata.cz/resource/dataset/product-open-data.org/2014-01-01>
];
rr:predicateObjectMap [
rr:predicateMap [rr:constant pod:bsin];
rr:objectMap [rr:termType rr:Literal; rr:column "BSIN" ];
];
rr:predicateObjectMap [
rr:predicateMap [rr:constant gr:name];
rr:objectMap [rr:termType rr:Literal; rr:column "BRAND_NM" ];
];
rr:predicateObjectMap [
rr:predicateMap [rr:constant s:url];
rr:objectMap [rr:termType rr:IRI; rr:template "{BRAND_LINK}";];
];.
', 'http://product-open-data.org/temp', 'http://product-open-data.org/temp', 0);
exec ('sparql ' || DB.DBA.R2RML_MAKE_QM_FROM_G ('http://product-open-data.org/temp','http://linked.opendata.cz/resource/dataset/product-open-data.org/2014-01-01'));
SPARQL Select * from <http://linked.opendata.cz/resource/dataset/product-open-data.org/2014-01-01>
where {?s ?o ?p.} limit 1000000;
My problem is following: I want to get a TTL file with dump_one_graph procedure. But when I run the procedure like this in iSQL:
SQL> DB.DBA.dump_one_graph('http://linked.opendata.cz/resource/dataset/product-open-data.org/2014-01-01','../R2RML/pod_',1000000000);
the only thing I get is:
Dump of graph http://linked.opendata.cz/resource/dataset/product-open-data.org/2014-01-01, as of 2014-11-11 23:46:48.000004
So my question is: where are my triples stored and why is SPARQL SELECT returning a result set while dump_one_graph doesn't?

R2RML gets mapped to Virtuoso RDFViews which are not persisted to the Quad Store by default.
There is an option to make these material or persisted to the Quad Store.
Have a look at: r2rml. There should by an option 'Enable Data Syncs with Physical Quad Store' which should do the trick. Also have a look at the Generate RDB2RDF triggers option. I don't know exactly how this will look with turtle-syntax, but you can inspect the resulting commands by using the 'Prepare to Execute Button.
Hope this helps...

Related

Select version string from JSON array and increment it by one using jq

Bash script find a a tags in ECR repo:
aws ecr describe-images --repository-name laplacelab-backend-repo
\ --query 'sort_by(imageDetails,& imagePushedAt)[*]'
\--output json | jq -r '.[].imageTags'
Output:
[
"v1",
"sometag",
...
]
How I can extract the version number? v<number> can contain the only version tag. I need to get a number and increment version for the set to var. If output of sort_by(imageDetails,& imagePushedAt)[*] is empty JSON arr instead
[
{
"registryId": "057296704062",
"repositoryName": "laplacelab-backend-repo",
"imageDigest": "sha256:c14685cf0be7bf7ab1b42f529ca13fe2e9ce00030427d8122928bf2d46063bb7",
"imageTags": [
"v1"
],
"imageSizeInBytes": 351676915,
"imagePushedAt": 1593514683.0
}
]
Set 2
No one repo sort_by(imageDetails,& imagePushedAt)[*] return [] set 1.
As a result, I try to get var VERSION with next version for an update or 1 if the repo is empty.
You could use the select() function on the imageTags array and get only the tag starting with v and increment it.
jq '( .[].imageTags[] | select(startswith("v")) | ltrimstr("v") | tonumber | .+1 ) // 1'
For other cases like the tags array being empty or containing null strings (error case), the value defaults to 1
For storing into the variable e.g. say version (avoid using uppercase variable names from a user scripts), use command substitution. See How do I set a variable to the output of a command in Bash?
version=$( <your-pipeline> )
Note: This does not work well with version strings following Semantic versioning RFC, e.g. as v1.2.1 as jq does not have a library to parse them.

How to dereference an uploaded URI node in Fuseki2 linked data server?

I installed Fuseki2 and run it as a standalone server with default settings (http://localhost:3030/).
I created an in-memory dataset ('geography') by uploading a Turtle file with information like this, through the 'Manage datasets' console:
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix schema: <http://schema.org/> .
#prefix dcat: <http://www.w3.org/ns/dcat#> .
#prefix pd: <http://localhost:3030/geography/ontology/> .
pd:City
rdf:type owl:Class ;
rdfs:comment "Represents a City in the ontology" .
<http://localhost:3030/geography/City/>
a dcat:Dataset;
schema:name "City information";
schema:description "Dataset with all the country's cities' information from 2018." ;
<http://localhost:3030/geography/City/1100015>
a pd:City;
rdfs:label "Rome" ;
pd:isCapital "1"^^xsd:int .
Although I can get the values by SPARQL query (eg. PREFIX dcat: http://www.w3.org/ns/dcat# SELECT ?s WHERE {?s a dcat:Dataset.}), I cannot access this node's information (http://localhost:3030/geography/City/1100015), as I would, for example , like this: http://dbpedia.org/page/Rome.
Is there a way that I can configure Fuseki server to dereference the URI that I uploaded and return the information of the node?
Apparently the only way to make the imported URIs resolvable is by using a Linked Data Interface, such as Pubby (http://wifo5-03.informatik.uni-mannheim.de/pubby/) or LOD View (https://github.com/LodLive/LodView).
Once installed, you can point them to the Fuseki's SPARQL endpoint.
Example with LodView config file (config.ttl):
conf:IRInamespace <http://localhost:3030/geography/> ; # base namespace for URIs
conf:endpoint <http://localhost:3030/sparql>; # where to query
The, you can access http://localhost:8080/lodview/geography/City/1100015 through content negotiation.

DynamoDB: How to append values into the List (Array) of an existing Item

(I'm using AWS PHP SDK)
Let's say i have a Table:
Table name: article
Primary partition key: article_id (Number)
With a sample of manually created Item:
{
"article_id": 10010,
"updated": "2018-02-22T20:15:19.28800Z",
"comments": [ "Nice article!", "Thank you!" ]
}
Adding new comment:
I know how to entirely update (overwrite) this existing Item, in this way:
$key = $marshaler->marshalJson('
{
"article_id": 10010
}
');
$eav = $marshaler->marshalJson('
{
":u": "2018-02-22T20:15:19.28800Z",
":c": [ "Nice article!", "Thank you!", "This is the new one!" ]
}
');
$params = [
'TableName' => 'article',
'Key' => $key,
'ExpressionAttributeValues'=> $eav,
'UpdateExpression' => 'set updated=:u, comments=:c',
'ReturnValues' => 'UPDATED_NEW'
];
I can somehow APPEND new values (aka) add new comment, this way. But this is literally still recreating the whole entire Item again, which is not the way i preferred.
How do i just simply APPEND new values into an List/Array inside an existing Item, please?
Add elements to the list
When you use SET to update a list element, the contents of that element are replaced with the new data that you specify. If the element does not already exist, SET will append the new element at the end of the list.
Create Table
aws dynamodb create-table \
--table-name article \
--attribute-definitions AttributeName=article_id,AttributeType=N \
--key-schema AttributeName=article_id,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
Add item
aws dynamodb put-item \
--table-name article \
--item '{
"article_id": {"N": "123"},
"updated": {"S": "00:00:00"},
"comments": {
"L": [
{ "S": "Nice article!" },
{ "S": "Thank you!" }
]}
}'
Update Item
aws dynamodb update-item \
--table-name article \
--key '{"article_id":{"N":"123"}}' \
--update-expression "SET comments[50] = :c, updated=:u" \
--expression-attribute-values '{
":u": {"S": "01:01:01"},
":c": {"S": "This is the new one!"}
}' \
--return-values ALL_NEW
List comments[] contain two elements (index 0 and 1) before the update. As comments[50] doesn't exist, the SET operation will append it to the end of the list (comments[2]).

How to do parse json array dynamically in shell script using jq too in shell script

Suppose I have the following json in a file json.txt
{
"first_name": "John",
"last_name": "Smith",
"things_carried": [
"apples",
"hat",
"harmonica"
],
"children": [
{
"first_name": "Bobby Sue",
"last_name": "Smith"
},
{
"first_name": "John Jr",
"last_name": "Smith"
}
]
}
In shell script I had written the logic to find the size of children array using jq tool .
size=cat json.txt | jq '.children | length'
i=0
while [ $i -le $size ]
do
array[$i]=$(cat json.txt | jq '.children[$i]')
i=`expr $i + 1`
done
On running this it gives the following error -
.children[$i] 1 compile error
It seems that it is not able to replace the variable i in the children[] array , as because if we give the expression -
array[$i]=$(cat json.txt | jq '.children[0]')
it runs well .
Can someone help me .
You're using single quotes around the jq program. Shells do not interpolate variables inside single quotes; this is intentional and the jq manual recommends using single quotes around programs for this reason.
An argument syntax is provided by jq for this purpose. This syntax allows you to set jq variables to the value of shell variables. You could replace your current jq invocation with this:
array[$i]=$(cat json.txt | jq --arg i $i '.children[$i | tonumber]')
It looks like you're just trying to set the children to a bash array variable.
You don't need to loop, just set the array directly.
$ IFS=$'\n'; array=($(jq -c '.children[]' json.txt))
You should use the following syntax:
array[$i]=$(cat json.txt | jq '.children['${i}']')

How to translate a first-order logic sentence into a restriction in Protègè with string matching?

I'm tring to build an ontology to infer some informations about a domain classification and a terminology, but I'm experiencing some conceptual difficulties.
Let me explain the problem. In Protègè 4.1 i created 6 subclasses of Thing: Concept, conceptTitle, ConceptSynonym (for the classification) and Term, TermTitle, TermSynonym (for the terminology). I also have created hasConceptTitle, hasConceptSynonym, hasTermTitle and hasTermSynonym object relationships (with some constrint) to say that every Concept has one (and only one) title, and may have some synonyms, and every Term has one (and only one) title and some synonyms. Both Concept and Term have another relationship isA, giving to the classification a DAG/tree structure, while the terminology has a lattice structure (in other words, a term may be a subclass of more than one term).
Here comes the problem: I would like to create a subclass of Concept, let's say "MappedConcept"), which should be the set of mapped concepts, that is the set of concepts which have the title equals to a term's title, or it has a synonym equals to a term's title or has a synonym that is equal to a synonym of a term.
In the first-order logic, this set may be expressed as:
∀x∃y( ∃z((hasConceptTitle(x,z) ∧ hasTermTitle(y,z)) ∨
∃z((hasConceptTitle(x,z) ∧ hasTermSynonym(y,z)) ∨
∃z((hasConceptSynonym(x,z) ∧ hasTermTitle(y,z)) ∨
∃z((hasConceptSynonym(x,z) ∧ hasTermSynonym(y,z)) )
How can I obtain this? Defining data properties for "ConceptTitle", "ConceptSynonym", "TermTitle" and "TermSynonym"? And how to describe the string matches?
Maybe those 4 classes should be just data properties of Concept and Term classes?
I read the practical guide of Matthew Horridge several times, but I can't the practical ideas I have on my mind into an ongology in Protègè.
Thanks in advance.
I'm afraid you cannot do this in OWL 2 DL nor in Protégé, which is an editor for OWL 2 DL, because, as far as I can tell, it seems necessary to introduce the inverse of a datatype property, which is forbidden in OWL 2 DL. However, it's possible in OWL Full, and some DL reasoners may even be able to deal with it. Here, in Turtle:
<MappedConcept> a owl:Class;
owl:equivalentTo [
a owl:Class;
owl:unionOf (
[
a owl:Restriction;
owl:onProperty <hasConceptTitle>;
owl:someValuesFrom [
a owl:Restriction;
owl:onProperty [ owl:inverseOf <hasTermTitle> ];
owl:someValuesFrom <Term>
]
] [
a owl:Restriction;
owl:onProperty <hasConceptTitle>;
owl:someValuesFrom [
a owl:Restriction;
owl:onProperty [ owl:inverseOf <hasTermSynonym> ];
owl:someValuesFrom <Term>
]
] [
a owl:Restriction;
owl:onProperty <hasConceptSynonym>;
owl:someValuesFrom [
a owl:Restriction;
owl:onProperty [ owl:inverseOf <hasTermSynonym> ];
owl:someValuesFrom <Term>
]
] [
a owl:Restriction;
owl:onProperty <hasConceptSynonym>;
owl:someValuesFrom [
a owl:Restriction;
owl:onProperty [ owl:inverseOf <hasTermTitle> ];
owl:someValuesFrom <Term>
]
]
)
] .
You can also do it without OWL, with a rule language for instance. The rules would look closer to how you would do it in programming languages. In SWRL:
hasConceptTitle(?x,?z), hasTermTitle(?y,?z) -> MappedConcept(?x)
hasConceptTitle(?x,?z), hasTermSynonym(?y,?z) -> MappedConcept(?x)
hasConceptSynonym(?x,?z), hasTermTitle(?y,?z) -> MappedConcept(?x)
hasConceptSynonym(?x,?z), hasTermSynonym(?y,?z) -> MappedConcept(?x)

Resources