SoftBank Robotics documentation What's new in NAOqi 2.8?

ALKnowledge API

NAOqi Core - Overview | API | Tutorial


Methods

void ALKnowledge::add(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object)

Adds a triple to the ontology.

The ontology is persistent so any added triple will stay in the ontology until it is removed by ALKnowledge::remove, ALKnowledge::resetKnowledge or ALKnowledge::update.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the triple.
std::vector<std::string> ALKnowledge::getSubject(const std::string& domain, const std::string& predicate, const std::string& object)

Gets the vector of all subjects given the predicate and the object.

Parameters:
  • domain – Domain of the predicate.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
Returns:

vector of all subjects for which the triple subject-predicate-object exists in the ontology.

std::vector<std::string> ALKnowledge::getPredicate(const std::string& domain, const std::string& subject, const std::string& object)

Gets the vector of all predicates given the subject and the object.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • object – Object of a triple.
Returns:

vector of all predicates (of the given domain) for which the triple subject-predicate-object exists in the ontology.

std::vector<std::string> ALKnowledge::getObject(const std::string& domain, const std::string& subject, const std::string& predicate)

Gets the vector of all objects given the subject and the predicate.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
Returns:

vector of all objects (of the given domain) for which the triple subject-predicate-object exists in the ontology.

void ALKnowledge::update(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object)

Removes all triples where the subject is subject and the predicate is predicate and add the triple subject-predicate-object.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the new triple
void ALKnowledge::remove(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object)

Removes the triple given the subject, predicate and object. The subject, predicate, object can be wildcard.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the triple.
bool ALKnowledge::contains(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object)

Checks if the ontology contains the given triple. The subject, predicate, object can be wildcard.

Parameters:
  • domain – Domain of the predicate
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the triple.
Returns:

True if the triple exists, false otherwise

std::vector<std::string> ALKnowledge::query(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object)

Returns the list of values satisfying the query given in parameters. The subject, predicate, object can be wildcard.

The parameters must contain 2 values and a question mark ”?” for the value you are looking for.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the triple.
Returns:

A vector of values.

    #Remove
    result = knowledge_service.remove("tutorial", "smurf", "hasColor", "red")
    result = knowledge_service.contains("tutorial", "smurf", "hasColor","red")
std::vector<std::string> ALKnowledge::query(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object)

Returns the list of triples satisfying the query given in parameters.

The parameters must contain 4 values and a question mark ”?” for the value you are looking for. The subject, predicate, object can be wildcard.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the triple.
  • metadataName – Metadata name of the triple.
  • metadataObject – Metadata value of the triple.
Returns:

A vector of values.

    """
    Example using metadata
std::vector<std::vector<std::string>> ALKnowledge::queryTriplet(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& metadataName, const std::string& metadataValue)

Returns the list of triples satisfying the query given in parameters. The subject, predicate, object can be wildcard.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the triple.
Returns:

A vector of vectors representing triples [domain, subject, predicate, object] satsifying the triple. Each vector containing successively ẗhe domain, subject predicate and object of the triple satisfying the query.

    #Give me everything which has a color
    result = knowledge_service.query("tutorial", "?", "hasColor", "*")
    print result #Should print ['sky', 'smurf']

void ALKnowledge::resetKnowledge(const std::string& domain)

Removes all the triples where the predicate is in the domain “domain”.

Parameters:
  • domain – Domain of the predicate.
bool ALKnowledge::addMetadata(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& metadataName, const std::string& metadataValue)

Adds a metadata to the given triple. If the triple does not exist, the triple will not be added but the metadata will be anyway.

The ontology is persistent so any metadata triple will stay in the ontology until it is removed by ALKnowledge::removeMetadata, ALKnowledge::resetKnowledge or ALKnowledge::updateMetadata. Metadas are not deleted when the triple to which they are linked is deleted. This allows to have a kind of history of triples within the ontology using basic metadatas.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the triple.
  • metadataName – Metadata name of the triple.
  • metadataObject – Metadata value of the triple.
Returns:

true if metadata is successfully added, false otherwise. Note that if the domain is different from com.aldebaran.learning then the metadata is not added and false is returned,

    """
    Example using metadata
bool ALKnowledge::updateMetadata(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& metadataName, const std::string& metadataValue)

Removes all the metadata with the name metadataName for the triple subject-predicate-object and add the the metadata metadataName-metadataValue.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • name (metadata) – Name of the metadata you want to update.
  • value (metadata) – New value of the metadata metadataName.
Returns:

true

    #Add triplet and metadatas to the ontology
    knowledge_service.add(domain, "user1", "eat", "pizza")
    knowledge_service.addMetadata(domain, "user1", "eat", "pizza", "with", "user2")
    knowledge_service.addMetadata(domain, "user1", "eat", "pizza", "with", "user3")
bool ALKnowledge::containsMetadata(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& metadataName, const std::string& metadataValue)

Checks if the ontology contains the metadata for this triple The subject, predicate, object can be wildcard.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • name (metadata) – Name of the metadata.
  • value (metadata) – Value of the metadata.
Returns:

True if the metadata exists, false otherwise

    #Query metadata
    result =  knowledge_service.query(domain, "user1", "eat", "pizza", "with")
    print result #Should print ['user2', 'user3']

    #Contains metadata
    result =  knowledge_service.updateMetadata(domain, "user1", "eat", "pizza", "with", "user4")
    result =  knowledge_service.queryMetadata(domain, "user1", "eat", "pizza", "with", "?")
bool ALKnowledge::removeMetadata(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& metadataName, const std::string& metadataValue)

Removes all the metadata with the name metadataName for the triple subject-predicate-object The subject, predicate, object can be wildcard.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • name (metadata) – Name of the metadata.
  • value (metadata) – Value of the metadata.
Returns:

True

    #Contains metadata
    bool contains  =  knowledge_service.containsMetadata(domain, "user1", "eat", "pizza", "with", "user4")
    print contains #Should print True
void ALKnowledge::queryMetadata(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& metadataName)

Gets the vector of all metadatas given the subject, predicate, object and metadata name The subject, predicate, object can be wildcard.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • name (metadata) – Name of the metadata you want to get the value.
Returns:

vector of all metadatas with the name metadataNamefor the triple subject-predicate-object in the ontology. Note that the triple doesn’t necessarily exist which means that ALKnowledge::contains could return False for this triple.

    """

    domain = "com.aldebaran.learning"
bool ALKnowledge::queryTripletWithMetadata(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& metadataName, const std::string& metadataValue, bool tripleExist)

Returns the list of triples and metadatas satisfaying the triple. The subject, predicate, object can be wildcard.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • name (metadata) – Name of the metadata.
  • value (metadata) – New value of the metadata metadataName.
Returns:

vector of triples and metadatas [domain, subject, predicate, object, metadataName, metadataValue]

std::string ALKnowledge::getId(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& metadataName, const std::string& metadataValue)

Returns the ID of a triple. This ID allows you to handle metadata (add, update, remove, contains) of a triple with the basic ALKnowledge methods.(ALKnowledge::add, ALKnowledge::update, ALKnowledge::remove ...)

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of the triple.
  • predicate – Predicate of the triple.
  • object – Object of the triple.
Returns:

The ID of the triple in the uuid format.

    print contains #Should print False
    contains  =  knowledge_service.containsMetadata(domain, "user1", "eat", "pizza", "with", "*")
    print contains #Should print True
std::vector<std::string> ALKnowledge::getTripletFromId(const std::string& domain, const std::string& tripleId)

Returns the triple associated with this ID.

Parameters:
  • domain – Domain of the predicate.
  • tripleId – ID of a triple.
Returns:

A vector representing the triple associated with this ID. [subject, predicate, object]

    #Remove metadata
    knowledge_service.removeMetadata(domain, "user1", "eat", "pizza", "with", "user4")
    contains  =  knowledge_service.containsMetadata(domain, "user1", "eat", "pizza", "with", "user4")
    print contains #Should print False

void ALKnowledge::addExpirationDate(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& expirationDate)

This function allows you to add the metadata expirationDate of a triple. The only difference with the method addMetadata using expirationDate as the metadata name is that this function checks if the last parameter has the format of a date (yyyy-MM-ddThh:mm:ssZ). If it’s not the case, it will not add the metadata. These functions allow you to add a triple and the metadata expirationDate at the same time. In case of addExpiringTime the function will add the duration to the current date then add the expirationDate metadata with this value

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • expirationDate – The date at which you want the triple to be removed.

Note that the triple removal can be delayed up to 30 sec.

void ALKnowledge::updateExpirationDate(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& expirationDate)

This function allows you to update the metadata expirationDate of a triple. The only difference with the method updateMetadata using expirationDate as the metadata name is that this function checks if the last parameter has the format of a date (yyyy-MM-ddThh:mm:ssZ). If it’s not the case, it will not add the metadata. These functions allow you to add a triple and the metadata expirationDate at the same time. In case of addExpiringTime the function will add the duration to the current date then add the expirationDate metadata with this value.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • expirationDate – The date at which you want the triple to be removed.

Note that the triple removal can be delayed up to 30 sec.

void ALKnowledge::addHappeningDate(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& happeningDate)

This function allows you to add the metadata happeningDate with a date posterior to the current date. This will cause the given triple to be automatically added at the given time. The only difference with the method addMetadata using happeningDate as the metadata name is that this function checks if the last parameter has the format of a date or a duration.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • happeningDate – The date at which you want the triple to be added.

Note that the triple can be added up to to 30 sec after the happeningDate.

void ALKnowledge::updateHappeningDate(const std::string& domain, const std::string& subject, const std::string& predicate, const std::string& object, const std::string& happeningDate)

This function allows you to update the metadata happeningDate with a date posterior to the current date. This will cause the given triple to be automatically added at the given time. The only difference with the method updateMetadata using happeningDate as the metadata name is that this function checks if the last parameter has the format of a date or a duration.

Parameters:
  • domain – Domain of the predicate.
  • subject – Subject of a triple.
  • predicate – Predicate of a triple.
  • object – Object of a triple.
  • happeningDate – The date at which you want the triple to be added.

Note that the triple can be added up to to 30 sec after the happeningDate.

Wildcard

A wildcard “*” can be used to represent any subject, predicate, object, medtadataName and metadataValue. Several wildcards can be used in the same method.