I want to write a sparql query to get rdf data based on their id. I am trying with
SELECT ?ID ?NAME WHERE {?ID = "something" }
but does not return the expecting results. Does anyone knows which is my mistake?
Actually rdf:id is the resource URI itself. You can utilise a SPARQL FILTER clause for filtering your result, or you can directly insert the URI in the WHERE clause of your query, e.g.
<myURI> ex:name ?name .
In order to have a precise answer you should share a small fragment of your RDF data (possibly in Turtle format, human friendly).
Related
I am a non programmer. I have a ontology in owl format. I also have an excel sheet (it contains data numeric data with headers of selected ontology). Now I have to connect the excel header with ontology framework and need to extract the links in excel data from the ontology.
Do I understand you correctly that you have an RDF knowledge base whose schema is described by an OWL ontology and you want to import this data from RDF to a spreadsheet?
The most straightforward case to transform RDF to spreadsheets is a SPARQL SELECT query.
Prerequisites
If you don't already have the data in an application or endpoint where you can query it directly (e.g. Protégé may have a widget for SPARQL queries), there are three prerequisites, else skip those:
1. Export/Convert the Data
If you have your data in an application where you can't perform SPARQL queries or as a file in a syntax such as OWL/XML, you need to convert it first, because most SPARQL endpoints don't understand this format, but rather need an RDF serialization such as N-Triples, RDF Turtle or RDF/XML, so you need to export the data in one of those formats.
2. Setup a SPARQL Endpoint
Now you can install e.g. a Virtuoso SPARQL endpoint, either locally or on a server or use the endpoint of someone else who gives you access credentials.
It can take a while to install but you can use a Docker image if that is easier.
3. Upload the Data
In Virtuoso SPARQL, you can now upload the ontology and the instance data in the conductor under "Linked Data" -> "Quad Store Upload".
Querying
I don't know of any existing tool that automatically maps ontologies and downloads instances according to a given Excel sheet templates so I recommend to create a SPARQL SELECT query manually.
Example
Let's say your Excel sheet has the header rows "name", "age" and "height" (you said you have numeric data) and the ontology has a person class defined like this in RDF Turtle:
:Person a owl:Class;
rdfs:label "Person"#en.
:age a owl:DatatypeProperty;
rdfs:label "age"#en;
rdfs:domain :Person;
rdfs:range xsd:nonNegativeInteger.
:height a owl:DatatypeProperty;
rdfs:label "height"#en;
rdfs:domain :Person;
rdfs:range xsd:decimal.
Now you can write the following SPARQL SELECT query:
PREFIX :<http://my.prefix/>
SELECT ?person ?age ?height
{
?person a :person;
:age ?age;
:height ?height.
}
This will generate a result table, which you can obtain in different formats. Choose the CSV spreadsheet format and then you can import it into MS Excel, which solves your problem as far as I interpret it.
As the tittle says I want to create some transactions to make queries. In my case I have Wallet and Customer classes and each of them has a type attribute for knowing what type they are. I want, for example to make a query to get all the wallets so I guess I would have to create a query like TYPE=WALLET. The code I use to query is the following.
String queryStr = "{\"selector\": {\"type\": \"wallet\"}}";
QueryResultsIterator<KeyValue> rows = stub.getQueryResult(queryStr);
The things that I don’t know who to structure the string for querying, of if there is a better way of doing this type of queries. Thanks for your help.
I m trying to sort the AEM query builder search results based on particular value of particular property. as we have in any database like MySQL we can sort based on column's value as well (for exp. ORDER BY FIELD('columnName','anyColumnName'). can we have something like this in AEM.
Suppose we have 5 Assets under path /content/dam/Assets.
Asset Name------------dc:title
1.jpg------------------Apple
2.jpg------------------Cat
3.jpg------------------Cat
4.jpg------------------Ball
5.jpg------------------Drag
I need assets on top of the results where dc:title = cat and also need other results also in sorting asc. expected result as given below
2.jpg------------------Cat
3.jpg------------------Cat
1.jpg------------------Apple
4.jpg------------------Ball
5.jpg------------------Drag
Note:- Using version AEM 6.2
You can use the orderby predicate with a value of #jcr:content/metadata/dc:title to sort by dc:title with the QueryBuilder. /libs/cq/search/content/querydebug.html is an interface to test queries on your instance. ACS Commons has a good breakdown of all out of the box predicates
If you want to pull Cats to the top of the results with a single query, you could write a custom predicate. The sample code from ACS Commons shows an example. Adobe has documentation as well.
I'm new user of mongoDB, I have create an application with spring boot/mySql and I want replace database sql to mongoDB.
I did change all things necessary for example, annotations, relations etc ... but I have a problem with request I don't know the similar syntax of #Query in mongoDb.
this my request with sql:
// this calculate the sum of all distance in walk's document
#Query("select sum(distance) from Walk")
public Double sumDistance();
I did read mongoDB aggregate and I know how to use it in console windows with command
$ mongo
$ db.walk.aggregate([{$group:{"_id":"$dateWalk",Count:{$sum:"$distance"}}}])
but, I want use $sum in my program java not in console.
So please, I need your help about the syntax similar to this with mongoDB
// this calculate the sum of all distance in walk's document
#Query("select sum(distance) from Walk")
public Double sumDistance();
thanks in advance :)
You would need to create a custom Repository that would implement the aggregation.
Examples:
https://www.javacodegeeks.com/2016/04/data-aggregation-spring-data-mongodb-spring-boot.html
https://github.com/spring-projects/spring-data-examples/blob/master/mongodb/aggregation/src/main/java/example/springdata/mongodb/aggregation/OrderRepositoryImpl.java
Spring Data Cassandra 1.5.0 comes with a streaming API in CassandraTemplate. I'm using spring-data-cassandra 1.5.1. I have a code like:
String tableName = cassandraTemplate.getTableName(MyEntity.class).toCql();
Select select = QueryBuilder.select()
.all()
.from(tableName);
// In real world, WHERE statement is much more complex
select.where(eq(ENTITY_FIELD_NAME, expectedField))
List<MyEntity> result = cassandraTemplate.select(select, MyEntity.class);
and want to replace this code with iterable or Java 8 Stream in order to avoid fetching a big list of results to memory at once.
What I'm looking for is a method signature like CassandraOperations.stream(Select query, Class<T> entityClass), but it is not available.
The only available method in CassandraOperations accepts query string: stream(String query, Class<T> entityClass). I tried to pass here a string generated by Select like
cassandraTemplate.stream(select.getQueryString(), MyEntity.class)
But that fails with InvalidQueryException: Invalid amount of bind variables, because getQueryString() returns query with question mark placeholders instead of variables.
I see 3 options to get what I want, but every option looks bad:
Use Spring Query creation mechanism with Stream/Iterator expected return type (good only for simple queries) http://docs.spring.io/spring-data/cassandra/docs/current/reference/html/#repositories.query-methods.query-creation
Use raw CQL query and not to use QueryBuilder
Call select.getQueryString() and then substitute parameters again via BoundStatement
Is there any better way to stream selection results?
Thanks.
So, as of now the answer on my question is to wait until stable version of spring-data-cassandra 2.0.0 comes out:
https://github.com/spring-projects/spring-data-cassandra/blob/2.0.x/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java#L208