Result of semantic's query sqwrl:makeBag - semantic-web

I have an example about ontology with only class Person and a try to create a collection throw sqwrl:makeBag
Person(?p) ˚ sqwrl:makeBag(?bag, ?p) ˚ sqwrl:size(?size, ?bag) -> sqwrl:select(?size)
And I have 4 individuals with type Person but when I run the query result is 1. I don't know why please help me thanks so much

Related

How to recursively query with sparql?

I have RDF like this:
<companyA> <heldBy> "companyB" .
<companyA> <heldBy> "companyC" .
<companyB> <heldBy> "companyD" .
It's a stockholder relation, what I wanna do is to query all holders of companyA and mark them by level.
For example, companyB is level 1, companyD is level 2.
How can I do this with sparql? Or is it doable with sparql?
Thanks for the help!
According to the comment section, I think this might be doable with querying all holders with select ?holder where { <companyA> <heldBy>+ ?holder }.
Then calculate the length of the path to these nodes, sort them into levels.
Might even do this with SPARQL only, working on it.
Thanks again for the help!

SPARQL-DL (derivo API) : Retrieving instances with a specific dataproperty string value

I'm trying to query an ontology in order to get all the instances of Person having the name "Andrea" with SPARQL-DL via owlapi:
SELECT ?i
WHERE { Type(?i, ns:Person), PropertyValue(?i, ns:name, "Andrea") }
I'm getting this:
[http-nio-8080-exec-10] org.primefaces.application.exceptionhandler.PrimeExceptionHandler.logException uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl.getInstance()Lorg/semanticweb/owlapi/model/OWLDataFactory;
java.lang.NoSuchMethodError: uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl.getInstance()Lorg/semanticweb/owlapi/model/OWLDataFactory;
at de.derivo.sparqldlapi.impl.QueryParserImpl.appendLiteral(QueryParserImpl.java:514)
at de.derivo.sparqldlapi.impl.QueryParserImpl.parseVariableBlankURILiteral(QueryParserImpl.java:450)
at de.derivo.sparqldlapi.impl.QueryParserImpl.parseAtom(QueryParserImpl.java:314)
at de.derivo.sparqldlapi.impl.QueryParserImpl.parseAtoms(QueryParserImpl.java:267)
at de.derivo.sparqldlapi.impl.QueryParserImpl.parseWhere(QueryParserImpl.java:192)
at de.derivo.sparqldlapi.impl.QueryParserImpl.parseSelect(QueryParserImpl.java:139)
at de.derivo.sparqldlapi.impl.QueryParserImpl.parseQueryHead(QueryParserImpl.java:111)
at de.derivo.sparqldlapi.impl.QueryParserImpl.parse(QueryParserImpl.java:67)
at de.derivo.sparqldlapi.Query.create(Query.java:106)
Thanks to all,
Andrea

DBpedia get all cities in the world - missing a few

I use this sparql query to get as much cities as possible:
select * where {
?city rdf:type dbo:PopulatedPlace
}
However, some expected ones are missing e.g.
http://dbpedia.org/resource/Heidelberg
(neither that nor one of its wikiRedirects)
which is of a dbo:PopulatedPlace as this query returns true (in JSON):
ask {
:Heidelberg a dbo:PopulatedPlace
}
I need that list to be exhaustiv because later I will add constraints based on user input.
I use http://dbpedia.org/snorql/ to test the queries.
Any help is appreciated.
UPDATE:
One of the Devs told me the public endpoint is limited ( about 1K ).
I'll come up with a paginated solution and see if it contains the 'outlier'.
UPDATE2:
The outlier is definitly in the resultset of rdf:type dbo:Town.
Using dbo:PopulatedPlace yields too many results to check per hand, though.
The public endpoint limits results to about 1K. Pagination or use of a smaller subclass of dbo:PopulatedPlace yields the result.

Count second level set of model in nhibernate

I want to count set of set of model in NHibernate using Criteria Query.
Account Model have Contacts(set) and Contact Model have Addresses(set).
I want to count addresses by giving input Account object.
I have implemented temporary by simple foreach loop.
If anyone know then please help me.
Thanks in advanced.
Thanks Radim Köhler,
I found my solution by :
var count = (Int32)Session.CreateCriteria(typeof(Account))
.Add(Restrictions.Eq("Id", account.Id))
.CreateCriteria("Contacts", "Contacts", JoinType.InnerJoin, Restrictions.IsNotEmpty("Addresses"))
.SetProjection(Projections.Count("Id")).UniqueResult(); .
Then I have used following criteria query:
var count = (Int32)Session.CreateCriteria(typeof(Address))
.CreateCriteria("Contact", "Contact",JoinType.InnerJoin)
.Add(Restrictions.Eq("Account.Id",accountId))
.SetProjection(Projections.Count("Id")).UniqueResult();
This give me actual result that I want by optimal query.

How to assign parameter values in a SparqlParameterizedString

I'm playing around some with Dotnetrdf's sparql engine and I'm trying to create parametered queries with no success yet.
Say I'm working on a graph g with a blank node identified as _:1690 with the code
Dim queryString As SparqlParameterizedString = New SparqlParameterizedString()
queryString.Namespaces.AddNamespace("rdfs", UriFactory.Create("http://www.w3.org/2000/01/rdf-schema#"))
queryString.CommandText = "SELECT ?label { #context rdfs:label ?label } "
queryString.SetParameter("context", g.GetBlankNode("1690"))
Dim result As VDS.RDF.Query.SparqlResultSet = g.ExecuteQuery(New SparqlQueryParser().ParseFromString(queryString))
Whenever I run this, I get all nodes having a rdfs:label property instead of filtering the result on my blank node only.
Please, how to set the parameter's value properly so I get only one item in the result ?
Thanks in advance,
Max.
Blank Nodes in a SPARQL query differ from Blank Nodes in a RDF Graph
In a SPARQL Query a blank node is treated as a temporary variable which has limited scope, it does not match a specific blank node so you cannot write a SPARQL query to select by blank node identifier.
So your code creating your query is giving a result the same as if you replaced #context with a variable e.g. ?s
If you need to find the value associated with a specific blank node then you need to formulate a query that uniquely selects that blank node based on the triples it participates in. If you can't do that then you need to re-think your data modelling since if this is the case then you should likely be using URIs instead of blank nodes.
As a workaround since you are using dotNetRDF and have the original graph you are querying you can use the IGraph API instead e.g.
INode label = g.GetTriplesWithSubjectPredicate(g.GetBlankNode("1690"), g.CreateUriNode("rdfs:label")).Select(t => t.Object).FirstOrDefault();
Just remember that label could always be null if the triple you are looking for doesn't exist