getting the label and description of wikidata item as well as specified properties labels and description - label

i am relatively new to sparql and i need to get the label/title of the wikidata item as well as other specified properties' label and description.
my code gives me only the properties' label and description but i cannot get the label/title and description of the wikidata item(qid). the label/title of the wikidata item(qid) - Building at Rua Esteves Junior, 26 and description of the wikidata item(qid) - historical site registered by State Institute of Cultural Heritage of Rio de Janeiro in the city of Rio de Janeiro, Rio de Janeiro, Brazil
my code:
SELECT ?locationDescription ?locationLabel ?streetLabel ?descriptionLabel ?countryLabel ?heritageLabel WHERE {
wd:Q69363514 wdt:P131 ?location.
wd:Q69363514 wdt:P6375 ?street.
wd:Q69363514 wdt:P973 ?description.
wd:Q69363514 wdt:P17 ?country.
wd:Q69363514 wdt:P1435 ?heritage.
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}

You could use VALUES:
SELECT
?item ?itemLabel ?itemDescription
?locationDescription ?locationLabel
?streetLabel
?descriptionLabel
?countryLabel
?heritageLabel
WHERE {
VALUES ?item { wd:Q69363514 }
?item wdt:P131 ?location ;
wdt:P6375 ?street ;
wdt:P973 ?description ;
wdt:P17 ?country ;
wdt:P1435 ?heritage .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
This would also allow you to query multiple items at once:
VALUES ?item { wd:Q69363514 wd:… wd:… }

Related

Orchard core GraphiQL does not display my added field

I started my project on Orchard Core Cms with .NET 6. When I try to execute graphql query on GraphiQL tool on Orchard Core it does not display the field "description" which I added to the fields of ProductCategory content item
The query is like below:
query MyQuery {
productCategory {
id
description
bag {
contentItems {
... on ProductCategory {
description
bag {
contentItems {
... on ProductCategory {
id
description
displayText
}
}
}
}
}
}
}
}
And the response is as follow:
{
"data": {
"productCategory": [
{
"id": 1,
"description": "Product Category 1 Description",
"bag": {
"contentItems": [
{
"bag": {
"contentItems": [
{
"id": 15,
// description field is absent
"displayText": "Product Category 3"
}
]
}
}
]
}
}
]
}
}
ProductCategory content type has two fields: Id and Description and enjoys Title, Flow, Bag, Alias parts. Moreover, this content type can be bag of ProductCategory content type. As it visible in the code, the first item displays the description field but the child item ignores it
I just needed to enable Autoroute feature and now everything works like a charm

Laravel query showing different Result in DB::Table and DB::Select with inner join

I'm using 3 table
1.organizations
2.users
3.organization_user
So the organization_user is the pivot table for getting org. and user.
DB::select("SELECT users.name 'User Name',organizations.name 'Org Name'
FROM users INNER JOIN organization_users ON
organization_users.user_id=users.id
INNER JOIN organizations ON
organizations.id=organization_users.organization_id
WHERE organization_users.organization_id=$org_id");
And getting the below result
[
{
"User Name": "Navid Anjum",
"Org Name": "org1"
},
{
"User Name": "kamal",
"Org Name": "org1"
} ]
But when using
DB::table('organization_users')
->join('users','users.id','=','organization_users.user_id')
->join('organizations','organizations.id','=',
'organization_users.organization_id')
->select('users.name as Name','organizations.name as Org Name')
->where('organization_users.id','=',$org_id)
->get();
And getting the below result
[
{
"Name": "Navid Anjum",
"Org Name": "org1"
} ]
So What I'm doing wrong?
you not set the right id for organization_users in the second statement :
DB::table('organization_users')
->join('users','users.id','=','organization_users.user_id')
->join('organizations','organizations.id','=',
'organization_users.organization_id')
->select('users.name as Name','organizations.name as Org Name')
->where('organization_users.organization_id','=',$org_id)
->get();

Shopify GraphQL partial matching on query filter

I'm just getting started with the new Shopify GraphQL Admin API. I'm trying to retreive all products, where the title field contains a certain word.
Currently I can successfully retrieve a product by including the full product title (exact match):
{
shop {
id
name
}
products(first: 10, query:"title:'RAVEN DUSTY OLIVE/SILVER MESH'") {
edges {
node {
productType
title
}
}
}
}
However, I want to partially match the title to display all products with the word "Raven" anywhere in the title, but the following returns no results:
{
shop {
id
name
}
products(first: 10, query:"title:'RAVEN'") {
edges {
node {
productType
title
}
}
}
}
Any ideas on how to get the partial matching working?
Bjorn! This should work:
{
shop {
id
name
}
products(first: 10, query:"title:RAVEN*") {
edges {
node {
productType
title
}
}
}
}
Check out the docs: https://help.shopify.com/en/api/getting-started/search-syntax
Also you can try with
query: "title:*${searchText}*"
you can see two * at the initial and the end

Retrieving label names with SPARQL query

I am having an issue with the Wikidata Query Service. https://query.wikidata.org/
What I want to do is retrieve a list of all persons who have a GTAA ID.
?q wdt:P1741 ?GTAA_ID.
For these persons, I want to retrieve the following optional information:
OPTIONAL{ ?q p:P166 ?award_received
OPTIONAL{ ?award_received pq:P585 ?point_in_time. }
OPTIONAL{ ?award_received pq:P1686 ?for_work. }
have received an award
at what point in time they received this award
for what work they received this award
As of now, my query mostly works. However, in the 'awards_received' column, for example, it is showing the following text:
wds:Q76343-ffa729dc-4d10-eb15-3a41-5fa6bf7ed80a
When clicking this it brings me to the Wikidata page concerning the person who received the award, NOT the title of the award itself.
What I would like to do is have the title of the received award retrieved, instead of a link to the receiver of the title.
The code I have is as follows:
SELECT ?GTAA_ID ?award_received ?point_in_time ?for_workLabel
WHERE
{
?q wdt:P1741 ?GTAA_ID.
OPTIONAL{ ?q p:P166 ?award_received
OPTIONAL{ ?award_received pq:P585 ?point_in_time. }
OPTIONAL{ ?award_received pq:P1686 ?for_work. }
. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "
[AUTO_LANGUAGE]". }
}
The actual award is given as the property ps:P166 of the statement:
SELECT ?GTAA_ID ?award ?awardLabel ?point_in_time ?for_workLabel {
?q wdt:P1741 ?GTAA_ID.
OPTIONAL {
?q p:P166 ?award_received .
?award_received ps:P166 ?award # Here
OPTIONAL { ?award_received pq:P585 ?point_in_time. }
OPTIONAL { ?award_received pq:P1686 ?for_work. }
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE]".
}
}
You can get a description of a resource with a DESCRIBE query, e.g.:
DESCRIBE wds:Q78217-3877ABD6-239F-47DA-A8BD-8035D3CBAA7A

How to get Company info from Google?

if we search website of the company in google we get following result. i need to get company info and founded year. and no of employee how can i get. is there any API availabe?. can you help me on this. thanks
You are looking for the Google knowledge graph API. The info on the box to the right is pulled from the Google Knowledge Graph for the top result.
You can get the information you need for an Organization entity:
An organization such as a school, NGO, corporation, club, etc.
Example properties of an Organization include legalName, logo, foundingDate
For example, here is a simple query I used for Facebook:
https://kgsearch.googleapis.com/v1/entities:search?query=Facebook&key=<YOUR_API_KEY_HERE>&indent=True
And here is the result I got in return:
{
"#type": "EntitySearchResult",
"result": {
"#id": "kg:/m/0hmyfsv",
"name": "Facebook, Inc.",
"#type": [
"Corporation",
"Organization",
"Thing"
],
"description": "Social network company",
"image": {
"contentUrl": "http://t3.gstatic.com/images?q=tbn:ANd9GcTjO7_7_DBuI3EpMBdVTACYT2WDkwKGrBic0JYSGtIt1c_0oMK9",
"url": "https://commons.wikimedia.org/wiki/File:F_icon.svg"
},
"url": "https://www.facebook.com/"
},
"resultScore": 32.638672
}
BTW, for some reason, Facebook was the second on the list of results after Youtube
Update
Looks like, at the moment, the API does not provide a way to control which properties to be returned in the results, and not all properties are included in the response by default. There is a question here about how to get that done
From the API reference, the accepted request paramaters are:
query (e.g. query=Facebook)
ids (e.g. ids=/m/0hmyfsv)
languages (e.g. languages=en)
types (e.g. types=Corporation)
indent (e.g. indent=true)
limit (e.g. limit=2)
And the response parameters are: #id, name,#type, description, image detailedDescription (if available), and resultScore
The information you are looking for are actually available in the Wikipedia page included in the URL provided as part of the detailedDescription property, so you may want to consider using the Wikidata API instead
Run following query in wikidata sparql endpoint
SELECT DISTINCT
?wdindustryLabel
?wdcompanyName
?wdcountryLabel
(SAMPLE(?wdemployee) AS ?wdemployee)
(SAMPLE(?wdfounded) AS ?wdfounded)
(SAMPLE(?wdofficial_website) AS ?wdofficial_website)
WHERE {
?wdcompany wdt:P31 ?type;
rdfs:label ?wdcompanyName.
OPTIONAL {
?wdcompany wdt:P452 ?wdindustry;
wdt:P1128 ?wdemployee;
wdt:P571 ?wdfounded;
wdt:P17 ?wdcountry;
wdt:P856 ?wdofficial_website.
}
FILTER(LANGMATCHES(LANG(?wdcompanyName), "EN"))
VALUES ?type {
wd:Q6881511
wd:Q43229
}
VALUES ?wdcompanyName {
"Apple Inc."#en
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?wdcompanyName ?wdindustryLabel ?wdcountryLabel
ORDER BY (?wdcompanyName)
or use following code:
# pip install sparqlwrapper
# https://rdflib.github.io/sparqlwrapper/
import sys
from SPARQLWrapper import SPARQLWrapper, JSON
endpoint_url = "https://query.wikidata.org/sparql"
query = """SELECT DISTINCT ?wdindustryLabel ?wdcompanyName ?wdcountryLabel (SAMPLE(?wdemployee) AS ?wdemployee) (SAMPLE(?wdfounded) AS ?wdfounded) (SAMPLE(?wdofficial_website) AS ?wdofficial_website) WHERE {
?wdcompany wdt:P31 ?type;
rdfs:label ?wdcompanyName.
OPTIONAL {
?wdcompany wdt:P452 ?wdindustry;
wdt:P1128 ?wdemployee;
wdt:P571 ?wdfounded;
wdt:P17 ?wdcountry;
wdt:P856 ?wdofficial_website.
}
FILTER(LANGMATCHES(LANG(?wdcompanyName), "EN"))
VALUES ?type {
wd:Q6881511
wd:Q43229
}
VALUES ?wdcompanyName {
'Apple Inc.'#en
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?wdcompanyName ?wdindustryLabel ?wdcountryLabel
Order By ?wdcompanyName"""
def get_results(endpoint_url, query):
user_agent = "WDQS-example Python/%s.%s" % (sys.version_info[0], sys.version_info[1])
# TODO adjust user agent; see https://w.wiki/CX6
sparql = SPARQLWrapper(endpoint_url, agent=user_agent)
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
return sparql.query().convert()
results = get_results(endpoint_url, query)
for result in results["results"]["bindings"]:
print(result)

Resources