Two "identical" answers to a request (utf8 and non-utf8) - utf-8

I am having problems with a live.dbpedia SPARQL request, for it returns some entries twice (once as an utf8 URI, once as a non-utf8 URI : Here are the results.
Is it something that needs to be fixed inside of dbpedia (where should it be reported)?
Is there a way to keep only one version of these duplicated urls? (I do not want to ignore a non-utf8 URI if there is no utf8 counterpart)
P.S.: The actual request
select distinct ?name where {
?name <http://purl.org/dc/terms/subject><http://dbpedia.org/resource/Category:Individual_graphs>.
} ORDER BY desc(?name) LIMIT 2

Even though there are multiple URIs that can identify the article, they all have the same article title, so you can extract the title (it's the value of the rdfs:label property), group by that, and then sample the URIs. Doing that, along with using the built-in DBpedia namespaces, I end up with this query:
select distinct (sample(?name_) as ?name) where {
?name_ dcterms:subject category:Individual_graphs ;
rdfs:label ?label
}
group by ?label
order by desc(?name)
SPARQL results

Related

How to properly perform like queries with Quickbase

I am working with quicktable queries and everything seems to be fine.
Now I want to perform queries using like operators. For instance in PHP I can do something like:
$data ='content to search';
$stmt = $db->prepare('SELECT * FROM members where name like :name OR email like :email limit 20');
$stmt->execute(array(
':name' => '%'.$data.'%',
':email' => '%'.$data.'%',
));
Now in quick table, I have tried using CT, EX or HAS parameter etc with OR Operators. Only CT gives nearby result but not exact as per code below.
//Email = 7
//name =8
{
"from": "tableId",
"where": "{7.CT.'nancy#gmail.com'}OR{8.CT.'nancy'}"
}
Is there any way I can obtain a better search with like operators with Quickbase. The documentation here does not cover that.
CT is the closest string comparison operator in Quick Base to LIKE in SQL, but since you can't use wildcards in Quick Base queries you might need to group multiple query strings to achieve the same result. The is also a SW operator that can sometimes come in helpful for comparing parts of a strings.

hyperledger-composer query with "CONTAINS" operator not working

In my hyperledger-composer app with angular front-end I want to send a query to the REST server.
query selectEmployeesByProject {
description: "Select all employees with access to the specified project"
statement:
SELECT org.comp.app.Employee
WHERE (projects CONTAINS [_$project])
ORDER BY [lastName, firstName]
}
Employee is defined as follows:
participant Employee {
o String lastName
o String firstName
--> Project[] projects optional
}
The http-request that is sent is the following:
this.httpClient.get<any[]>(requestURL, {withCredentials: true});
whereby the request url is the following:
http://localhost:4200/api/queries/selectEmployeesByProject?projects=resource:org.comp.app.Project#project1ID
In the console I get the following error message:
Failed to load resource
http://localhost:4200/api/queries/selectEmployeesByProject?projects=resource:org.comp.app.Project#project1ID
the server responded with a status of 400 (Bad Request)
Why is the query not working?
In general, httpRequests to the REST-server work in my app. Even other queries work. However, queries with the "CONTAINS" operator (such as the one above) do not work.
more likely to be
query selectClientsByProjects {
description: "Select all clients with access to a certain project"
statement:
SELECT org.myComp.myApp.Client
WHERE (projects CONTAINS [_$project])
ORDER BY [lastName ASC, firstName ASC]
}
Note: At the time of writing - CouchDB does not allow the ORDER BY clause to contain multiple items of different sort direction (obviously not the case above).
Also - not tested but your http call may need to be:
this.http.get('http://localhost:4200/api/queries/selectClientsByProjects?projects=resource:org.myComp.myApp.Project%231')
(%23 is the ASCII for '#')
You can try it out your definition first anyway (eg. without ORDER BY maybe) etc etc. Note: CONTAINS must match one entry ('array contains an element, with complete string match (above), in any element, in that array)

Search query from joined table in Laravel 5.3

I have a books table that contains many subject on my subjects table (one-to-many relationship).
I tried to join my tables like this:
$book = Book::latest()
->leftjoin('subjects', 'books.id', '=', 'subjects.book_id')
->select('books.*', 'subjects.subject')
->where('subject', 'like', '%' .$search. '%')
->paginate(20);
I want a search query that will display the books having subjects matched form the $search variable. However, it keeps displaying a book redundantly depending on how many subjects of a book that matched on the $search variable since a book has many subjects.
I only want to display a book once, regardless of how many subjects the book matched.
This image below was the output of the search query I made, the value of the $search= ""
On the second image notice that I search "a" on the search box:
The book entitled "Special Education assessment: Issues strategies affecting today's classrooms" (see it on the first image; it was being redundant 6 times since the subjects of that book was 6)
To display a book only once you have to group by book id (or any other unique column)
->groupBy('books.id');
Mind you, as mentioned in the MySQL doc here
SQL92 and earlier does not permit queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are not named in the GROUP BY clause.
Hence the error message 'bisu_ccc_library.books.ISBN' isn't in GROUP BY
To bypass this, turn off strict in Laravel and everything will work nicely.
Go to config/database.php and in the mysql configuration array, change strict => true to strict => false
I think you want to use distinct for your select
$book = Book::latest()
->leftjoin('subjects', 'books.id', '=', 'subjects.book_id')
->select('books.*', 'subjects.subject')
->distinct()
->where('subject', 'like', '%' .$search. '%')
->paginate(20);
Just like in regular SQL (which it will translate to) it will "Force the query to only return distinct results." (from laravel api docs)
The SELECT DISTINCT statement is used to return only distinct
(different) values.
Inside a table, a column often contains many duplicate values; and
sometimes you only want to list the different (distinct) values.
The SELECT DISTINCT statement is used to return only distinct
(different) values. - W3Schools

Sorting movie cast members by role relevancy

I'm using the following query to retrieve all cast members for "Star Wars - The Force Awakens" using its IMDb identifier (tt2488496).
The problem is that the results are not sorted accordingly, for example, I would like to see some main characters like John Boyega, Adam Driver, Daisy Ridley, etc. appear on the top most section of the result, but the results just seem random.
For example, IMDb sorts by top-billed cast, and I don't know if wikidata has that kind of info, but if we look into the wikidata page for the Star Wars - The Force Awakens title (https://www.wikidata.org/wiki/Q6074), in the cast member section, you will see that they are sorted properly.
Is there any way to achieve the same sorting that wikidata has on their title page?
SPARQL query (link):
SELECT ?titleLabel ?castLabel ?castImdb WHERE {
VALUES ?imdbIds { "tt2488496" }
?title wdt:P345 ?imdbIds .
?cast wdt:P345 ?castImdb .
?title wdt:P161 ?cast .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}

Why this SPARQL query don't work into Prolog?

I am trying to integrate SPARQL queries into Prolog program (I am using SWI-Prolog)
To test it I am doing the following operations:
Into SWI-Prolog shell I execute this command: use_module(library(semweb/sparql_client)). that load the sparql client library
Then, in the SWI-Prolog shell, I execute the following SPARQL query:
?- sparql_query('select count(*) where { ?person a http://dbpedia.org/ontology/Person .?person http://it.dbpedia.org/property/nome ?name.filter regex(?name,"Leonardo"). }', Row, [ host('dbpedia.org'), path('/sparql/')]).
Row = row(literal(type('http://www.w3.org/2001/XMLSchema#integer', '0'))).
I don't know well SPARQL but I think that this is pretty simple and that work in this way:
This query ask about the instances number of objects that are considered personal names on a RDF ontology called dbpedia, passing the input parameter "Leonardo".
As you can see the problem seems that don't find any instance of this type (I have tried also with others personal name)
Why? What are am I missing?
Your query does not return what you want it to return. You can use SPARQL interactively with the DBpedia SPARQL endpoint. I suggest that you use that to debug your query and make sure it returns what you would like first, and then copy it into your Prolog program. You can build it up in pieces to make sure it's giving suitable results. For instance, start with something like the following:
select * where {
?person a <http://dbpedia.org/ontology/Person> .
}
LIMIT 10
SPARQL results
Then expand it piece by piece:
select * where {
?person a <http://dbpedia.org/ontology/Person> .
?person <http://it.dbpedia.org/property/nome> ?name .
}
LIMIT 10
SPARQL results
This query doesn't return anything, so it would be best to debug it before continuing on the the FILTER or COUNT.
After playing with the endpoint for a while, it seems that using REGEX is going to be kind of expensive, as are other string operations. If you can query for the strings you want directly, you might be better off. Unfortunately, you'll need to start working with language tags, too. For instance, here is a query that counts people with the given name or surname "Leonardo".
select COUNT(?person) where {
?person a dbpedia-owl:Person .
{ ?person foaf:givenName "Leonardo" }
UNION
{ ?person foaf:surname "Leonardo" }
}
SPARQL results
It returns 0. However, if we add (English) language tags to those strings, we get different results (133):
select COUNT(?person) where {
?person a dbpedia-owl:Person .
{ ?person foaf:givenName "Leonardo"#en }
UNION
{ ?person foaf:surname "Leonardo"#en }
}
SPARQL results

Resources