direct answer to sparql select query of equivalent class for graphdb? - select

I have an "EquivalentTo" definition in Protege of a class EquivClass as (hasObjProp some ClassA) and (has_data_prop exactly 1 rdfs:Literal)
Is there a form of SPARQL query for GraphDB 9.4 to get the "direct" answer to a select query of an equivalent class without having to collect and traverse all the constituent blank nodes explicitly? Basically, I'm looking for a short cut. I'm not looking to get instances of the equivalent class, just the class definition itself in one go. I've tried to search for answers, but I'm not really clear on what possibly related answers are saying.
I'd like to get something akin to
(hasObjProp some ClassA) and (has_data_prop exactly 1 rdfs:Literal)
as an answer to the SELECT query on EquivClass. If the answer is "not possible", that's enough. I can write the blank node traversal with the necessary properties myself.
Thanks!!
Files are -
Ontology imported into GraphDB: tester.owl - https://pastebin.com/92K7dKRZ
SELECT of all triples from GraphDB *excluding* inferred triples: tester-graphdb-sparql-select-all-excl-inferred.tsv - https://pastebin.com/fYdG37v5
SELECT of all triples from GraphDB *including* inferred triples: tester-graphdb-sparql-select-all-incl-inferred.tsv - https://pastebin.com/vvqPH1FZ
Added sample query in response to #UninformedUser. I use "select *" for example, but really I'm interested in the "end results", ie, ?fp, ?fo, ?rop, ?roo. Essentially, I'm looking for something simpler and more succinct than what I have below.The example I posted only has a single intersection ("and" clause). In my real world set, there are multiple equiv classes with different numbers of "and" clauses.
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <http://www.semanticweb.org/ontologies/2020/9/tester#>
select * where {
:EquivClass owl:equivalentClass ?bneq .
?bneq ?p ?bnhead .
?bnhead rdf:first ?first .
?first ?fp ?fo .
?bn3 rdf:rest ?rest .
?rest ?rp ?ro .
?ro ?rop ?roo .
filter(?bn3 != owl:Class && ?ro!=rdf:nil)
}

You can unroll the list using a property path:
prefix : <http://www.semanticweb.org/ontologies/2020/9/tester#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select * {
:EquivClass owl:equivalentClass/owl:intersectionOf/rdf:rest*/rdf:first ?restr.
?restr a owl:Restriction .
optional {?restr owl:onProperty ?prop}
optional {?restr owl:cardinality ?cardinality}
optional {?restr owl:someValuesFrom ?class}
}
This returns:
| | restr | prop | cardinality | class |
| 1 | _:node3 | :hasObjProp | | :ClassA |
| 2 | _:node5 | :has_data_prop | "1" ^^xsd:nonNegativeInteger | |

Related

SPARQL: Combine two select statements that each have a GROUP BY clause

Hello I am trying to find the total number of municipalities a region has along with the name of each region and the total number of municipalities a regional unit has along with the name of the regional unit. A region consists of regional units and a regional unit consists of municipalities. Below is my query that unfortunately returns wrong results. What I am basically trying to do is group by region and get the name and the total municipalities of each region and group by regional unit and take the name and the total municipalities of each unit. Any suggestions to the right direction would be appreciated. Cheers!:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema
PREFIX strdf: <http://strdf.di.uoa.gr/ontology
PREFIX gag: <http://geo.linkedopendata.gr/gag/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?region ?municipality_region ?unit ?municipality_unit
WHERE
{
{ SELECT ?region (COUNT(?municipality) AS ?municipality_region)
{?m rdf:type gag:Δήμος .
?m gag:έχει_επίσημο_όνομα ?municipality .
?m gag:ανήκει_σε ?reg_un .
?reg_un gag:ανήκει_σε ?reg .
?reg gag:έχει_επίσημο_όνομα ?region .
}GROUP BY ?region}
{ SELECT ?unit (COUNT(?municipality_un) AS ?municipality_unit)
{ ?m rdf:type gag:Δήμος .
?m gag:έχει_επίσημο_όνομα ?municipality_un .
?m gag:ανήκει_σε ?reg_un .
?reg_un gag:έχει_επίσημο_όνομα ?unit .
} GROUP BY ?unit}
};
Below I am giving a mapping of properties in english:
Δήμος = municipality
έχει_επίσημο_όνομα = has name
ανήκει_σε = belongs to
And here is the ontology I am working with:
link

find pattern relationships using rest cypher

how can I find pattern relationships using rest cypher?
My query running on terminal :-
MATCH (n)<-[:DEPENDS_ON*]-(dependent) RETURN n.host as Host,
count(DISTINCT dependent) AS Dependents ORDER BY Dependents
DESC LIMIT 1**
output is :-
+--------------------+
| Host | Dependents |
+--------------------+
| "SAN" | 20 |
+--------------------+
where as equivalent query with rest :-
String query = "{\"query\" : \"MATCH (website)<-[rel]-(dependent) " +
"WHERE TYPE(rel) = {rtype} RETURN website.host as Host," +
"count(DISTINCT dependent) AS Dependents ORDER BY Dependents DESC LIMIT 1" +
" \", \"params\" : {\"rtype\" : \"DEPENDS_ON*\"}}";
and output is empty(no records) !!!
Any help appreciated.
P.S- When we dont use "*" in our query everything goes ok. IE both queries give same result
In the second query you are passing the relationship type as "DEPENDS_ON*" which is incorrect since the asterisk is being included.
The asterisk is for allowing arbitrary length paths for the specified relationship but is not part of the type.

XText cross-reference to rule containing a cross-reference

The following is a simple representation of an xtext grammar with cross references.
There are two entities - a container and an object - and operations on each. I would like to be able to refer to an object either by it's own name, or qualified with the container name. I would like cross-references to be available in either case.
The grammar I have is:
Model:
operations+=Operation*;
ContainerEntity:
name=ID;
ObjectEntity:
(first=[ContainerEntity] '.')? name=ID
;
Operation:
CreateContainer | CreateObject | ContainerOp | ObjectOp
;
CreateContainer:
'Container' container=ContainerEntity ';'
;
CreateObject:
'Object' object=ObjectEntity ';'
;
ContainerOp:
'ContainerOp' name=[ContainerEntity] ';'
;
ObjectOp:
'ObjectOp' name=[ObjectEntity] ';'
;
And the editor statements are:
Container c;
Object o;
ContainerOp c;
ObjectOp o;
ObjectOp c.o; // ERROR: Couldn't resolve reference to ObjectEntity 'c'.
Note that it does not recognize "c" as a ContainerEntity. What can I do to make this work the way I described?

postgresql + textsearch + german umlauts + UTF8

I'm really at my wits end, with this Problem, and I really hope someone could help me. I am using a Postgresql 9.3. My Database contains mostly german texts but not only, so it's encoded in utf-8. I want to establish a fulltextsearch wich supports german language, nothing special so far.
But the search is behaving really strange,, and I can't find out what I am doing wrong.
So, given the following table given as example
select * from test;
a
-------------
ein Baum
viele Bäume
Überleben
Tisch
Tische
Café
\d test
Tabelle »public.test«
Spalte | Typ | Attribute
--------+------+-----------
a | text |
sintext=# \d
Liste der Relationen
Schema | Name | Typ | Eigentümer
--------+---------------------+---------+------------
(...)
public | test | Tabelle | paf
Now, lets have a look at some textsearch examples:
select * from test where to_tsvector('german', a) ## plainto_tsquery('Baum');
a
-------------
ein Baum
viele Bäume
select * from test where to_tsvector('german', a) ## plainto_tsquery('Bäume');
--> No Hits
select * from test where to_tsvector('german', a) ## plainto_tsquery('Überleben');
--> No Hits
select * from test where to_tsvector('german', a) ## plainto_tsquery('Tisch');
a
--------
Tisch
Tische
Whereas Tische is Plural of Tisch (table) and Bäume is plural of Baum (tree). So, Obviously Umlauts does not work while textsearch perfoms well.
But what really confuses me is, that a) non-german special characters are matching
select * from test where to_tsvector('german', a) ## plainto_tsquery('Café');
a
------
Café
and b) if I don't use the german dictionary, there is no Problem with umlauts (but of course no real textsearch as well)
select * from test where to_tsvector(a) ## plainto_tsquery('Bäume');
a
-------------
viele Bäume
So, if I use the german dictionary for Text-Search, just the german special characters do not work? Seriously? What the hell is wrong here? I Really can't figure it out, please help!
You're explicitly using the German dictionary for the to_tsvector calls, but not for the to_tsquery or plainto_tsquery calls. Presumably your default dictionary isn't set to german; check with SHOW default_text_search_config.
Compare:
regress=> select plainto_tsquery('simple', 'Bäume'),
plainto_tsquery('english','Bäume'),
plainto_tsquery('german', 'Bäume');
plainto_tsquery | plainto_tsquery | plainto_tsquery
-----------------+-----------------+-----------------
'bäume' | 'bäume' | 'baum'
(1 row)
The language setting affects word simplification and root extraction, so a vector from one language won't necessarily match a query from another:
regress=> SELECT to_tsvector('german', 'viele Bäume'), plainto_tsquery('Bäume'),
to_tsvector('german', 'viele Bäume') ## plainto_tsquery('Bäume');
to_tsvector | plainto_tsquery | ?column?
-------------------+-----------------+----------
'baum':2 'viel':1 | 'bäume' | f
(1 row)
If you use a consistent language setting, all is well:
regress=> SELECT to_tsvector('german', 'viele Bäume'), plainto_tsquery('german', 'Bäume'),
to_tsvector('german', 'viele Bäume') ## plainto_tsquery('german', 'Bäume');
to_tsvector | plainto_tsquery | ?column?
-------------------+-----------------+----------
'baum':2 'viel':1 | 'baum' | t
(1 row)

PostgreSQL LIKE operator doesn't match hyphen

I've a problem with LIKE operator in PostgreSQL. It does not match patterns that contain the - character. I've tried to escape these characters using the ESCAPE option, but it still does not work.
Query:
select * from footable where trascrizione like '% [---]is Abraam %';
Sample data (contents of column trascrizione):
[---]is Abraam [e]t Ise[---] / ((crux quadrata))
How can I solve this problem?
That pattern would not match because there is no space before [---]is Ambraam. There is a space in your pattern, between the % and [ characters, and it's requiring that space to be in your data. Try LIKE '%[---]is Abraam %'.
Please show the code. I have no problem:
SELECT * FROM a WHERE a LIKE '%-' AND b LIKE '%-%' AND c LIKE '-%';
a | b | c | d | e
------+---+------+---+---
foo- | - | -bar | |
(1 Zeile)