I can't seem to understand actions and goal in pddl - pddl

I have problem understanding pddl, I'm trying to make a spaceship plan, spaceship can move to a region as long as captain and navigator is at the bridge.
This is my code for action from domain file
(:action travel :parameters (?x ?y)
:precondition (and (REGION ?x) (REGION ?y) ; travel between regions
(at-region ?x) (at-bridge ?x) (at-bridge ?y))
:effect (and (at-region ?y)
(not (at-region ?x)))
)
when i try this problem file
(:init (SUBMARINE submarine)
(ROOM bridge) (ROOM sickbay) ; 2 rooms - bridge and sickbay
(PERSONNEL captain) (PERSONNEL navigators)
(REGION regionempty) (REGION seaport)
(at-region seaport) (at-bridge captain) (at-bridge navigators)
)
(:goal (and (at-region regionempty))
)
I get error : ff: goal can be simplified to FALSE. No plan will solve it

The issue lies in the precondition of your action and its parameters. You declare only two parameters ?x and ?y. For those you require five things to hold in order for the travel action to be executable:
(region ?x)
(region ?y)
(at-region ?x)
(at-bridge ?x)
(at-bridge ?y)
The problem are number 4 and 5. ?x and ?x should be the regions between you want to travel (that is what 1.-3.) express. But then you say that the region ?x must also be at the bridge (4.) and that the region ?y must be at the bride (5.). The point here is that for an instance of the travel action you have to select one value for each variable s.t. all preconditions hold at the same time.
What fixes your problem is to add two additional parameters:
(:action travel :parameters (?x ?y ?p1 ?p2)
:precondition (and (REGION ?x) (REGION ?y) ; travel between regions
(at-region ?x) (at-bridge ?p1) (at-bridge ?p1))
:effect (and (at-region ?y)
(not (at-region ?x)))
)
Lastly, you are untyped PDDL and check types with unary predicates. This is quite outdated. For modelling purposes you should always use typed variables. I.e. introduce types region, personnel, submarine, ... The action definition then looks like this:
(:action travel :parameters (?x ?y - region ?p1 ?p2 - personnel)
:precondition (and (at-region ?x) (at-bridge ?p1) (at-bridge ?p1))
:effect (and (at-region ?y)
(not (at-region ?x)))
)

Related

How to get the number of languages a Wikipedia page is available in? (SPARQL query)

I'm trying to have a list of Italian books from the 1980 on and the number of Wikipedia pages their original Wikipedia page has been translated into, for instance I would like to have:
Book, number
The name of the Rose, 5
Where 5 is the number of languages The Name of the Rose has been translated into in Wikipedia, for instance there is an English wiki page, a Dutch one, a Spanish one, a French one, a Greek one.
Here is the query so far:
SELECT ?item ?label
WHERE
{
VALUES ?type {wd:Q571 wd:Q7725634} # book or literary work
?item wdt:P31 ?type .
?item wdt:P577 ?date FILTER (?date > "1980-01-01T00:00:00Z"^^xsd:dateTime) . #dal 1980
?item rdfs:label ?label filter (lang(?label) = "it")
?item wdt:P495 wd:Q38 .
}
I get the list of books, but I can't find the right property to look for.
Did you actually get The Name of the Rose in your example? Because its date of publication is set to 1980 (which is = 1980-01-01 for our purposes), I had to change your query to a >= comparison.
Then, using COUNT() and GROUP BY as mentioned in the comment gets you what you want. But if you really just need the number of sitselinks, there is a shortcut that may be useful. It was added because that number is often used as a good proxy for an item's popularity, and using the precomputed number is vastly more efficient than getting all links, grouping, and counting.
SELECT ?book ?bookLabel ?sitelinks ?date WHERE {
VALUES ?type { wd:Q571 wd:Q47461344 wd:Q7725634 }
?book wdt:P31 ?type;
wdt:P577 ?date;
wdt:P495 wd:Q38;
wikibase:sitelinks ?sitelinks.
FILTER((?date >= "1980-01-01T00:00:00Z"^^xsd:dateTime) && (?date < "1981-01-01T00:00:00Z"^^xsd:dateTime))
SERVICE wikibase:label { bd:serviceParam wikibase:language "it,en". }
}
Query
Note that the values may slightly differ from the version with group & count because here sites such as commons or wikiquote are also included.

Recreate Wikipedia list of states by GDP with SPARQL query

I am trying to recreate this list:
https://en.wikipedia.org/wiki/List_of_states_and_territories_of_the_United_States_by_GDP
with a Wikidata SPARQL query.
I can find states by population with this query
Additionally, the fields:
population (P1082)
GDP (P2131)
And some extra ones, like unemployment (P1198)
are covered by the wikiproject economics, though only at the country level.
That said, seeing the "List of states and territories of the United States by GDP" article makes me think at least P2131 may be available at the state level.
I have tried the following query.
SELECT DISTINCT ?state ?stateLabel ?population ?gdp
{
?state wdt:P31 wd:Q35657 ;
wdt:P1082 ?population ;
wdt:P2131 ?gdp ;
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?state ?population ?stateLabel ?gdp
ORDER BY DESC(?population)
And see no matches. What's the right query for this?
(Point in time for a given year would be excellent, like how the table gives me 2019, 2020, etc., but I'll settle for learning the vanilla first.)
Because of a Wikidata internal convention, I had to upload the GPD data in the items about the States' economies, that are linked through property P8744.
E.g., for the State of Maine you'll find the data in economy of Maine.
This is the correct query for obtaining what you want (test):
SELECT DISTINCT ?state ?stateLabel ?population ?gdp (year(?date) as ?year)
{
?state wdt:P31 wd:Q35657 ;
wdt:P1082 ?population ;
wdt:P8744/wdt:P2131 ?gdp .
?gdpStmt ps:P2131 ?gdp ;
pq:P585 ?date .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?state ?population ?stateLabel ?gdp ?date
ORDER BY DESC(?year) DESC(?population)
It also considers grouping by year.

Multiple population for a cities in WikiData

I am doing a query on cities population and would like to calculate the percentage of city population with respect to their counties. But there are multiple populations for each city due to the year, therefore would like to take the latest version.
#List of countries ordered by the number of their cities with female mayor
#added before 2016-10
SELECT ?country ?countryLabel ?countryPopulation ?city ?cityLabel ?cityPopulation (?cityPopulation / ?countryPopulation AS ?ratio) #(year(?date) as ?dateyear)
WHERE
{
?city wdt:P31/wdt:P279* wd:Q515 . # find instances of subclasses of city
?city wdt:P17 ?country . # Also find the country of the city
?city wdt:P1082 ?cityPopulation . # city population
?country wdt:P1082 ?countryPopulation .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
}
#ORDER BY DESC(?count)
LIMIT 100
For example here I get multiple entries with different values corresponding to the population of wd:Q9954
** UPDATE
Based on my understanding from a similar question here I tried to update my code - but still, I am not confident whether I am forming my query correctly. Also, I have to add that, I would like to calculate the city_population / country_population which even after filtering doesn't seem to hold. I appreciate your comments.
SELECT ?country ?countryLabel ?countryPopulation ?city ?cityLabel ?cityPopulation ?ciy_date
WHERE
{
#?city wdt:P31/wdt:P279* wd:Q515 .
#?city wdt:P1082 ?cityPopulation .
#?country wdt:P1082 ?countryPopulation .
?city wdt:P31/wdt:P279* wd:Q515 .
?city p:P1082 ?populationStatement .
?populationStatement ps:P1082 ?cityPopulation;
pq:P585 ?ciy_date .
?city wdt:P17 ?country .
?country wdt:P1082 ?countryPopulation .
FILTER NOT EXISTS {
?country p:P1081/pq:P585 ?hdi_country_date_ .
?city p:P1082/pq:P585 ?hdi_city_date_ .
FILTER (?hdi_city_date_ > ?ciy_date)
FILTER (?hdi_country_date_ > ?hdi_country_date_)
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
}
#ORDER BY DESC(?count)
LIMIT 100

How to convert some queries from sql to sparql?

I am just learning Sparql and I have the following tables:
Countries, European Country, City and Capital
I would like to know how to make the following queries, because I didnt understand them...
1) Which country has the city "Paris" as capital.
2) Print all the European Countries
3) Print all the countries and theis capitals.
Thank you very much in advance.
This said, there is DBpedia that offers info similar to what is described, and is a good playground. To query it, http://yasgui.org (which is a better sparql editor) or http://factforge.net/sparql (which is our own integration, a few months old, but has some extra goodies).
Which country has the city "Paris" as capital
select * {
?x a dbo:Country; dbo:capital dbr:Paris
}
The yasgui results will surprise you:
dbr:Bourbon_Restoration
dbr:France
dbr:Francia
dbr:French_Fifth_Republic
dbr:Kingdom_of_France
dbr:Office_International_d'Hygiène_Publique
dbr:Second_French_Empire
dbr:West_Francia
I understand all the historic kingdoms, but dbr:Office_International_d'Hygiène_Publique is a bit of a shock. The reason is that it's an International Organization (uses Infobox Former International Organization, and it redirects to https://en.wikipedia.org/wiki/Template:Infobox_former_country, which "is currently being merged with Template:Infobox country". See http://mappings.dbpedia.org/index.php/Cleaning_up_Countries
factforge returns even more results from linked datasets (all these mean just France):
geodata:3017382/
http://ontologi.es/place/FR
http://psi.oasis-open.org/iso/3166/#250
leaks:country-FRA
wfr:fr
All the European Countries
That's better because there happens to be a Wikipedia category:
select * {
?x a dbo:Country; dct:subject dbc:Countries_in_Europe
}
yasgui
all countries and their capitals
select * {
?x a dbo:Country; dbo:capital ?capital
}
This returns a bunch of historic countries and capitals, and again some international organizations, eg
League_of_Nations
International_Authority_for_the_Ruhr
Japanese_occupation_of_British_Borneo
SO THEN, you may have better luck with Wikidata (https://query.wikidata.org/). At https://twitter.com/search?q=wikidatafacts%20country you can find a bunch of interesting queries related to countries.
countries and capitals on Wikidata
select ?country ?countryLabel ?city ?cityLabel {
?country wdt:P36 ?city
filter exists {?country wdt:P31/wdt:P279* wd:Q6256}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en,pl,ru,es" .
}
} order by ?countryLabel
It uses a bunch of Qnn and Pnn but you can decode them when you mouse-over.
How did I find that wdt:P36 means "capital"? Search for property:capital
why filter exists? Because a country may have several subtypes of wd:Q6256 "country", and if I use that in the main query, it returns several results per country. This way it returns only one.
Map
You can also easily display it on a map:
#defaultView:Map
select ?country ?countryLabel ?city ?cityLabel ?coords {
?country wdt:P36 ?city
filter exists {?country wdt:P31/wdt:P279* wd:Q6256}
?city wdt:P625 ?coords
SERVICE wikibase:label {bd:serviceParam wikibase:language "en,pl,ru,es"}
}
See a couple of shots https://twitter.com/valexiev1/status/844870994942603264

Wikidata Sparql: how to get a list of actors that where never directed by a given person?

Let's say I want a list of actors that were never directed by Tim Burton among a list of popular movies.
I tried to do it with this steps:
Select all actors that Tim Burton ever directed (sub select)
Select a list of actors from a list of popular movies (by imdb ids)
Exclude all actors from the first selection in the second selection (NOT IN)
Here is a code I tried that do not works (the NOT IN fail, I don't know why):
SELECT DISTINCT ?actor ?actorLabel
WHERE {
?film wdt:P31 wd:Q11424
;wdt:P161 ?actor
;wdt:P345 ?imdbId .
{
SELECT ?excludeActors
WHERE {
?film wdt:P31 wd:Q11424
; wdt:P57 wd:Q56008
; wdt:P161 ?excludeActors .
}
} .
FILTER(?actor NOT IN (?excludeActors)) .
FILTER(?imdbId = "tt1077368" || ?imdbId = "tt0167260") .
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" }
}
Or follow this link
(there is a filter on Christopher Lee that you can remove [last one], it is used to highlight what I explain here:)
In this code I have two movies: Dark Shadows (directed by Tim Burton) and The Lord of the Rings 3. In this example Christopher Lee is present in both movies, which means he should be excluded since Tim Burton directed him in Dark Shadows.
You can see that he his in the list.
I really don't understand why the NOT IN fail with the sub select. I tried the sub Select request and I found Christopher Lee inside which means he should be excluded.
If I understood correctly, you want all actors that acted in the given movies, but have never acted in any movie directed by Tim Burton. I would use FILTER NOT EXISTS:
SELECT DISTINCT ?actor ?actorLabel
WHERE {
VALUES ?imdbId { "tt1077368" "tt0167260" }
?film wdt:P31 wd:Q11424
;wdt:P161 ?actor
;wdt:P345 ?imdbId .
FILTER NOT EXISTS {
[] wdt:P31 wd:Q11424
; wdt:P57 wd:Q56008
; wdt:P161 ?actor .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" }
}
LIMIT 100