Attributes#

You can add any kind of attributes to Annotations. Attributes are very useful, because you can make your searches more granular:

Event@(theme="weather") 'in' UK
-----
"drought in england"
"rain in oxford"
"heatwaves in britain"

The syntax is simple:

Annotation@(attributeName="attribute value");

You can set attributes with the same name, for instance if there is ambiguity:

lexicon: {Paris} = City@(country="France",country="USA");

The value of an attribute is a string, so you can use blanks in them.

Static Attributes#

Static attributes are those that you set statically in a lexicon, they do not vary:

lexicon: { "Ulf Kristersson" } = PrimeMinister@( country="sweden" );
lexicon: { "EyeOnText" } = Company@( office="belgium" , office="sweden" );

Runtime Attributes#

In runtime attributes, you can set the value of the attribute using the runtime data and the f-string functionality (python like). You can also use python string functions such as upper(), replace(), etc.

att = f"MySpecial_{capture.country}_{rule.Person.Given.gender.upper()}"
Would result in : att="MySpecial_belgium_FEMALE"

In the following example we capture the name of a Person which is a Sport player.(Sport being a Concept which as all the sports). Then we add a attribute sport to SportsPerson with the value of Sport

Rule:

rule :
{
    {
        (Prop)+
    } = SportsPerson@(sport=f"{rule.Sport.stem()}")
    "is" "a" Sport "player"
};

Output:

Rafael Nadal is a tennis player”
SportsPerson
- sports=”tennis”
Lionel Messi is a football player”
SportsPerson
- sports=”football”

f-string attribute format#

F-string attributes have to start with the scope where the attribute will be searched in.

different type of scope Concept

  • rule : Which spans the search scope of the currently matched rule.

  • capture : Which spans the search scope to the { … }= section.

  • sentence : Which spans the search scope to the sentence.

ex : Using the rule above:

            Rafael Nadal is a tennis player that has won 22 Grand Slam.
rule:       -------------------------------
capture     ------------
sentence    -----------------------------------------------------------

From a Concept, ask for attributes or sub annotations or call some functions:

Attribute#

Request a attribute from a given concept which will return a str

Person@(gender=f"{capture.gender}")
    "is" "a"
    Sport
    "player"
};

Sub Annotations#

Request a sub annotation from a given concept which will return a Concept

Person@(givename=f"{capture.GivenName.literal()}")

Functions#

There are available functions:

  • literal() : (str) return the literal of the given Concept.

  • stem() : (str) return the stem of the given Concept.

  • canonical() : (str) return the canonical form of the given Concept.

This is a more complex example:

rule:
{
Person .. Address
} = PersonAddress@(postal_code=f"{rule.Address.PostalCode.lower().replace('.','')}" name=f"{rule.Person.title()}")

Deleting Attributes#

You can delete attributes by deleting the Annotation and reassigning it again.

In the example below, we see that the mentioned city is an American city. We can delete all the rest of country attributes and just leave USA as a country:

//------------------------------
//  Paris , Texas
//------------------------------
rule:
{
        {
            {
                City
            } = wow::filter@(concept="City",country=/(?!USA).+/)
        } = City@(country="USA")
    <'\,'>
    USState
};