PDDL Predicate name must be a string - pddl

I am trying to solve a planning assignment with pddl and i wrote the following domain
(define (domain Monster)
(:requirements :strips)
(:predicates (player ?p) (location ?x) (monster ?m) (treasure ?tr) (trap ?tp) (weapon ?w) (flyer ?f) ;entities
(playerat ?player ?location) (monsterat ?monster ?location) (trapat ?trap ?location) (treasureat ?trasure ?location) (weaponat ?weapon ?location) (flyerat ?flyer ?location); relations
(gameOver ?p) (holdsw ?p) (holdsf ?p) (holdst ?p) (go ?A ?B) (close ?A ?B)
)
(:action Move ;Move from location A to location B
:parameters (?P ?A ?B ?M) ; P->Player A->Location_1 B->Location_2
:precondition (and(player ?P) (location ?A) (location ?B) (monster ?M) (playerat ?P ?A) (go ?A ?B) (not(monsterat ?M ?B)) )
:effect (and(playerat ?P ?B) (not(playerat ?P ?A)) )
)
(:action PickWeapon ; picking up weapon
:parameters (?P ?L ?W) ;P->player L->location W->Weapon
:precondition (and(player ?P) (location ?L) (weapon ?W) (playerat ?P ?L) (weaponat ?W ?L) )
:effect (and(holdsw ?P) (not(weaponat ?W ?L)))
)
(:action PickFlyer ;picking up flyer
:parameters (?P ?L ?F) ;P->player L->location F->flyer
:precondition (and(player ?P) (location ?L) (flyer ?F) (playerat ?P ?L) (flyerat ?F ?L) )
:effect (and(holdsf ?P) (not(flyerat ?F ?L)) )
)
(:action PickTreasure ;picking up treasure
:parameters (?P ?L ?T) ;P->player L->location T->treasure
:precondition (and(player ?P) (location ?L) (treasure ?T) (playerat ?P ?L) (treasureat ?T ?L) )
:effect (and(holdst ?P) (not(treasureat ?T ?L)) )
)
(:action PlayerKilled ;player killed
:parameters (?P ?L ?M) ;P->player L->location M->monster
:precondition (and(player ?P) (location ?L) (monster ?M) (playerat ?P ?L) (monsterat ?M ?L) (not(holdsw ?P)) (not(holdsf ?P)) )
:effect (and(gameOver ?P) (not(playerat ?P ?L)) ); Game Over
)
(:action PlayerTraped ;Player traped
:parameters (?P ?L ?TR) ;P->player L->location TR->trap
:precondition (and(player ?P) (location ?L) (trap ?TR) (playerat ?P ?L) (trapat ?TR ?L) (not(holdsf ?P)) )
:effect (and(gameOver ?P) (not(playerat ?P ?L)) )
)
(:action Kill ;Killing Monster
:parameters (?P ?A ?M ?B) ;P->player L->location M->monster
:precondition (and(player ?P) (location ?B) (location ?A) (monster ?M) (playerat ?P ?A) (monsterat ?M ?B) (holdsw ?P) (close ?A ?B) (go ?A ?B) )
:effect (and(playerat ?P ?B) (not(monsterat ?M ?B)) (not(holdsw ?P)) )
)
(:action FlyOverMonster
:parameters (?P ?F ?L ?A ?M) ;P->player L->location F->flyer M->monster
:precondition (and(player ?P) (location ?L) (location ?A) (monster ?M) (playerat ?P ?A) (monsterat ?M ?L) (holdsf ?P) (close ?A ?L) (go ?A ?L) )
:effect (and(playerat ?P ?L) (not(holdsf ?P)) )
)
(:action FlyOverTrap
:parameters (?P ?F ?L ?A ?TR) ;P->player L->location F->flyer TR->trap
:precondition (and(player ?P) (location ?L) (location ?A) (trap ?TR) (playerat ?P ?A) (trapat ?TR ?L) (holdsf ?P) (close ?A ?L) (go ?A ?L) )
:effect (and(playerat ?P ?L) (not(holdsf ?P)) )
)
)
problem
i defined the problem to be planned as follows
(define (problem Monster2)
(:domain Monster)
(:objects a b c d e f g h i pl mo tp fl tr wp
)
(:init
(location a) (location b) (location c) (location d) (location e) (location f) (location g) (location h) (location i)
(player pl) (monster mo) (trap tp) (flyer fl) (treasure tr) (weapon wp)
(go a b) (go b a) (go b c) (go c b) (go c d) (go d c) (go a e) (go e b) (go e f) (go f d) (go e g) (go e h) (go h e) (go h i) (go i h)
(close b c) (close c d) (close e f)
(playerat pl a) (monsterat mo c) (treasureat tr d) (trapat tp f) (weaponat wp h) (flyerat fl i)
)
(:goal (and
(holdst pl)
(playerat pl a)
)
)
)
Trying to solve the problem i Changed my code but now I am facing another problem. The agent after killing the monster does not go to the next room but he returns back and then jambs to d room collects the treasure and stay at d. The strange thing is that the planer says that the agent is now at room c and in next state it says he is at room b.
Planner result
Planer Kill Monster agent at room c
Planner result
Planner Move next supposed to be room d and it says room b state which is wrong

Actually there are several mistakes in the PDDL file. I tested it with FF.
In the domain file you missed some AND and few parenthesis in different action definitions, e.g.
(:action Kill
:parameters (?P ?L ?M ?A) ;P->player L->location M->monster
:precondition (and(player ?P) (location ?L) (location ?A) (monster ?M) (atp ?P ?A) (atm ?M ?L) (holdsw ?P ?W) (close ?A ?L) )
:effect (and (not(atm ?M ?L)) (not(holdsw ?P ?W)) (atp ?P ?L))
)
Then you forgot to declare some predicates used in domain definition, e.g. at1...at6, located
Then in actions FlyOverMonster and FlyOverTrap you forgot to declare variable ?A, variable ?W in actions Kill and PlayerKilled.
In action PlayerKilled you have a predicate hold that doesn't appear anywhere else.
I don't continue, but I hope that the corrections are clear. Then, the planner should point out the kind of error it encounters.

Check your predicates name, I am not sure numbers are supported in their names, and in their parameter names.
In your problem, I can see occurrences of at1, at2, etc... These predicates are named strangely, and I am suspicious it is meant to work.
Moreover, they are not declared in your domain.

Related

How to return subgraph from rdf graph

I have an RDF graph G with several classes assuming for simplicity (Person and Parrot).
The class Person is connected to the class Parrot by the property hasAnimal, e.g.:
#PREFIX : <http://example.org/>
:Hugo rdf:type :Person .
:Hugo rdfs:label "Hugo" .
:Hugo :hasAnimal :Birdy.
:Birdy rdf:type :Parrot .
:Birdy rdfs:label :"Birdy" .
:LonleyBrido rdf:type :Parrot .
What is wanted is a subgraph of G that contains all the triples from Person and Parrot that are directly connected with each other, starting from Person. The initial Person does not matter to me, the important part is that only connected triples are extracted i.e. that only persons that do have a parrot or don't get outputted. What I have already tried is the following:
construct {
?person ?p ?o .
?parrot ?p2 ?o2 .
} where {
?person rdf:type :Person .
?person ?p ?o .
?person :hasAnimal ?parrot .
?parrot rdf:type :Parrot .
?parrot ?p2 ?o2 .
}
So the expected output would be:
:Hugo rdf:type :Person .
:Hugo rdfs:label "Hugo" .
:Hugo :hasAnimal :Birdy.
:Birdy rdf:type :Parrot .
:Birdy rdfs:label :"Birdy" .
I am executing this query on a rdflib graph.
Does anyone have a solution to this problem?
The solution is already described above:
import rdflib
from rdflib.namespace import RDF, RDFS
query = """
construct {
?person ?p ?o .
?parrot ?p2 ?o2 .
} where {
?person rdf:type :Person .
?person ?p ?o .
?person :hasAnimal ?parrot .
?parrot rdf:type :Parrot .
?parrot ?p2 ?o2 .
}
"""
g = rdflib.Graph()
g.parse("example.ttl", format="ttl")
g.bind("rdf", RDF)
g.bind("rdfs", RDFS)
EX= rdflib.Namespace("http://example.org/")
g.bind("example", EX)
result = g.query(query)

PDDL doesn't compile

Trying to figure out this PDDL problem of getting robots to clean tiles but I'm stuck with what I'm doing wrong as far as I understand, I have the movements actions and clean actions only for up and down yet it still doesnt compile. It just gives me an error that says could not parse domain file.
This is the domain:
(define (domain floor-tile)
(:requirements :typing)
;; We have two types: robots and the tiles, both are objects
(:types robot tile - object)
;; define all the predicates as they are used in the probem files
(:predicates
;; described what tile a robot is at
(robot-at ?r - robot ?x - tile)
;; indicates that tile ?x is above tile ?y
(up ?x - tile ?y - tile)
;; indicates that tile ?x is below tile ?y
(down ?x - tile ?y - tile)
;; indicates that tile ?x is right of tile ?y
(right ?x - tile ?y - tile)
;; indicates that tile ?x is left of tile ?y
(left ?x - tile ?y - tile)
;; indicates that a tile is clear (robot can move there)
(clear ?x - tile)
;; indicates that a tile is cleaned
(cleaned ?x - tile)
)
(:action clean-up
:parameters (?r - robot ?x - tile ?y - tile )
:precondition (and (up ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (not (clear ?y)) (cleaned ?y)
)
(:action clean-down
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (down ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (not (clear ?y)) (cleaned ?y)
)
(:action up
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (up ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (robot-at ?r ?y) (not(robot-at ?r ?x)))
)
(:action down
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (down ?y ?x) (robot-at ?r ?x)(clear ?y))
:effect (and (robot-at ?r ?y)
(not(robot-at ?r ?x)))
)
(:action right
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (right ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (robot-at ?r ?y)
(not(robot-at ?r ?x)))
)
(:action left
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (left ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (robot-at ?r ?y )
(not(robot-at ?r ?x)))
)
)
Here is the problem:
(define (problem prob001)
(:domain floor-tile)
(:objects tile_0-1 tile_0-2
tile_1-1 tile_1-2
tile_2-1 tile_2-2 - tile
robot1 - robot
)
(:init
(robot-at robot1 tile_1-1)
(clear tile_0-1)
(clear tile_0-2)
(clear tile_1-2)
(clear tile_2-1)
(clear tile_2-2)
(up tile_1-1 tile_0-1)
(up tile_1-2 tile_0-2)
(up tile_2-1 tile_1-1)
(up tile_2-2 tile_1-2)
(down tile_0-1 tile_1-1)
(down tile_0-2 tile_1-2)
(down tile_1-1 tile_2-1)
(down tile_1-2 tile_2-2)
(right tile_0-2 tile_0-1)
(right tile_1-2 tile_1-1)
(right tile_2-2 tile_2-1)
(left tile_0-1 tile_0-2)
(left tile_1-1 tile_1-2)
(left tile_2-1 tile_2-2)
)
(:goal (and
(cleaned tile_0-1)
(cleaned tile_0-2)
(cleaned tile_1-1)
(cleaned tile_2-2)
))
)
Brackets are missing on the :effect of both clean-up and clean-down. After adding those brackets, the online editor's solver indicates that the goal trivially can't be reached, but at least it parses.

SPARQL query fetch properties of resources

I have a triple store and would like to create a query. This is an example of a resource representing a single deed:
<http://natarchives.com.mt/deed/MS588-D52>
locah:accessProvidedBy <http://natarchives.com.mt/repository/MT01> ;
locah:associatedWith "heredes" , "honorabilis" , "uncias" , "per tactum penne" , "vinea" , "ut moris est" , "juribus" , "unciarum" , "precij" , "spacium" , "gracia" , "tabernam sitam" , "honorabili" , "renunciantes" , "territorio" , "testes" , "tarenos" , "recuperacionis consuetudinarie" , "positam" , "ponderis" , "post" , "tabernam" , "causa" , "per se" , "sed sponte jure" , "diaconus" , "cisterna" , "precio" , "civitate" , "festo" , "solvere" ;
locah:associatedWith <http://natarchives.com.mt/person/person11817> , <http://natarchives.com.mt/person/person11826> , <http://natarchives.com.mt/person/person11822> , <http://natarchives.com.mt/person/person11820> , <http://natarchives.com.mt/person/person11823> , <http://natarchives.com.mt/person/person11818> , <http://natarchives.com.mt/place/place486> , <http://natarchives.com.mt/person/person11824> , <http://natarchives.com.mt/person/person11825> , <http://natarchives.com.mt/person/person11821> , <http://natarchives.com.mt/person/person11816> , <http://natarchives.com.mt/place/place886> , <http://natarchives.com.mt/person/person11819> ;
locah:level <http://data.archiveshub.ac.uk/page/level/item> ;
dcterms:date "1-10-1467" ;
dcterms:identifier "MS588-D52" ;
dcterms:isPartOf <http://natarchives.com.mt/archivalresource/MS588> ;
dcterms:type "Emptio" .
I am trying to search the deed by date. The result should show:
deed id, type, register URI - in this case (http://natarchives.com.mt/archivalresource/MS588), register Id, repository URI (http://natarchives.com.mt/repository/MT01), repository name, keywords associated with the deed and the people and places associated with deed. For people and places I would like to get other properties such as name, surname. This is what I have so far:
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX locah: <http://data.archiveshub.ac.uk/def/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX schema: <http://schema.org/>
SELECT ?id ?type ?register ?regId ?rep ?repName ?associatedEntities
WHERE
{
{
{
SELECT ?id ?type ?register ?regId ?rep ?repName (group_concat(concat(str(?places)," # ",?placeName); separator=" | ") as ?associatedEntities)
WHERE {
?x dcterms:date "22-1-1487".
?x dcterms:identifier ?id.
?x dcterms:type ?type.
?x locah:associatedWith ?places.
?places schema:name ?placeName.
?x dcterms:isPartOf ?register.
?register dcterms:identifier ?regId.
?x locah:accessProvidedBy ?rep.
?rep rdfs:label ?repName.
FILTER (isURI(?places)).
}
GROUP BY ?id ?type ?register ?regId ?rep ?repName
}union{
SELECT ?id ?type ?register ?regId ?rep ?repName (group_concat(concat(str(?persons)," # ",?name); separator=" | ") as ?associatedEntities)
WHERE {
?x dcterms:date "22-1-1487".
?x dcterms:identifier ?id.
?x dcterms:type ?type.
?x locah:associatedWith ?persons.
?persons foaf:firstName ?name.
?x dcterms:isPartOf ?register.
?register dcterms:identifier ?regId.
?x locah:accessProvidedBy ?rep.
?rep rdfs:label ?repName.
FILTER (isURI(?persons)).
}
GROUP BY ?id ?type ?register ?regId ?rep ?repName
}
}
}
I managed to get both but is it possible to group the results of the union

SPARQL - Query based on some property

I want to get all the pizza names which has cheese toppings but the result shows (_:b0) which is kind of an owl restriction following is my query
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT ?X WHERE {
?X rdfs:subClassOf* [
owl:onProperty pizza:hasTopping ;
owl:someValuesFrom pizza:CheeseTopping
]
}
using Pizza ontology from stanford
This works (Without reasoning enabled)
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT ?X ?topping WHERE {
?X rdfs:subClassOf ?Y .
?Y owl:someValuesFrom ?topping .
?topping rdfs:subClassOf* pizza:CheeseTopping
}
ORDER BY ?X
Some are listed more than once as they could contain more than one CheeseTopping. To remove duplicates:
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT DISTINCT ?X WHERE {
?X rdfs:subClassOf ?Y .
?Y owl:someValuesFrom ?topping .
?topping rdfs:subClassOf* pizza:CheeseTopping
}
ORDER BY ?X
This works if you enable a reasoner:
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT DISTINCT ?X WHERE {
?X rdfs:subClassOf pizza:CheeseyPizza
}
Ref:
Used the pizza ontology from here: http://protege.stanford.edu/ontologies/pizza/pizza.owl
That query works but is really complex and might be incomplete because some pizzas use complex OWL constructs:
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT DISTINCT ?pizza WHERE {
{
?pizza rdfs:subClassOf* pizza:Pizza .
?pizza owl:equivalentClass|rdfs:subClassOf [
rdf:type owl:Restriction ;
owl:onProperty pizza:hasTopping ;
owl:someValuesFrom/rdfs:subClassOf* pizza:CheeseTopping
]
} UNION {
?pizza owl:equivalentClass _:b0 .
_:b0 rdf:type owl:Class ;
owl:intersectionOf _:b1 .
_:b1 (rdf:rest)*/rdf:first ?otherClass.
?otherClass rdf:type owl:Restriction ;
owl:onProperty pizza:hasTopping ;
owl:someValuesFrom/rdfs:subClassOf* pizza:CheeseTopping
}
}

SPARQL group concat union

I'm trying to GROUP_CONCAT a UNION of two sets of triples.
Is this not allowed?
PREFIX bo: <https://webfiles.uci.edu/jenniyk2/businessontology#>
SELECT (GROUP_CONCAT(DISTINCT ?m2;SEPARATOR = ", ") AS ?comp)
WHERE
{
{{SELECT ?m2 ?c ?p
WHERE { ?c rdfs:label ?m. ?c2 rdfs:label ?m2. ?so bo:owner ?p.
?so bo:sharesIn ?c. ?so2 bo:owner ?p. ?so2 bo:sharesIn ?c2. }
}
UNION
{SELECT ?m2 ?c ?p
WHERE { ?c rdfs:label ?m. ?c2 rdfs:label ?m2. ?dir bo:isPartOf ?c.
?dir bo:isDirectedBy ?p. ?dir2 bo:isPartOf ?c2. ?dir2 bo:isDirectedBy ?p.}
}}
GROUP BY ?c
HAVING (COUNT(?m2) >1)}
It says there's an error in the very last line.
Found group. Was expecting one of : BIND, BLANK_NODE_LABEL, DECIMAL,
DOUBLE, FALSE, FILTER, GEO, GRAPH, INTEGER, MINUS, NIL-SYMBOL, OPTIONAL,
Q_IRI_REF, QNAME, QNAME_NS, SERVICE, STRING_LITERAL1, STRING_LITERAL2,
STRING_LITERAL_LONG1, STRING_LITERAL_LONG2, TEXTINDEX, TRUE, UNION, VALUES,
VARNAME or punctuation '(', '+', '-', '.', '[', '[]', '{', '}'.
The GROUP BY and HAVING clauses should be outside the WHERE clause, not inside it as they currently are. To make your query syntactically correct, remove the closing } from the last line and add it on the line above your GROUP BY:
PREFIX bo: <https://webfiles.uci.edu/jenniyk2/businessontology#>
SELECT (GROUP_CONCAT(DISTINCT ?m2;SEPARATOR = ", ") AS ?comp)
WHERE
{
{{SELECT ?m2 ?c ?p
WHERE { ?c rdfs:label ?m. ?c2 rdfs:label ?m2. ?so bo:owner ?p.
?so bo:sharesIn ?c. ?so2 bo:owner ?p. ?so2 bo:sharesIn ?c2. }
}
UNION
{SELECT ?m2 ?c ?p
WHERE { ?c rdfs:label ?m. ?c2 rdfs:label ?m2. ?dir bo:isPartOf ?c.
?dir bo:isDirectedBy ?p. ?dir2 bo:isPartOf ?c2. ?dir2 bo:isDirectedBy ?p.}
}}}
GROUP BY ?c
HAVING (COUNT(?m2) >1)
As Joshua also indicated, the query can be written a lot simpler, but this should solve your immediate problem.
Jeen Broekstra's answer identifies the typographical problem that causes your syntax error, but I think it's worth mentioning that this query can be simplified a bit, because simpler code from the beginning makes it easier to spot typos and syntax errors when they arise. If I read it correctly, it looks like the body of the query simplifies to this:
?c rdfs:label ?m .
?c2 rdfs:label ?m2 .
{ ?so bo:owner ?p ;
bo:sharesIn ?c .
?so2 bo:owner ?p ;
bo:sharesIn ?c2 . }
union
{ ?dir bo:isPartOf ?c ;
bo:isDirectedBy ?p .
?dir2 bo:isPartOf ?c2 ;
bo:isDirectedBy ?p }
You're looking for a ?c that's connected by one of two certain types of path to a ?c2, and you want to group by ?c and concatenate the distinct labels of ?c2. I see two ways that this could be simplified further. The first is with the use of property paths, since you don't actually use the values of many of these variables. With property paths, the body could become:
?c rdfs:label ?m .
?c2 rdfs:label ?m2 .
{ ?c ^bo:sharesIn/bo:owner/^bo:owner/bo:sharesIn ?c2 }
union
{ ?c ^bo:isPartOf/bo:isDirectedBy/^bo:isDirectedBy/bo:isPartOf ?c2 }
As another alternative, since the structure of the pattern in each union alternative is similar, you could abstract a bit with values:
?c rdfs:label ?m .
?c2 rdfs:label ?m2 .
values (?sharesIn_isPartOf ?owner_isDirectedBy) {
(bo:sharesIn bo:owner)
(bo:isPartOf bo:isDirectedBy)
}
?x ?owner_isDirectedBy ?y ;
?sharesIn_isPartOf ?c .
?x2 ?owner_isDirectedBy ?y ;
?sharesIn_isPartOf ?c2 .