Categories and Objects

Categories and Objects

Categories and Objects are how Blawx organizes what it knows about the world.

A Category is a type of object. An easy way to think of a Category is as a description of a blank form. The form might have a name, like “Application for a Permit”. That is like the Category name. A form will also have fields on that form that can be filled in, like “Applicant’s Name”. Those are like the category’s attributes.

When you create and fill out an actual form of that type, that is like creating an Object. The filled-out form is not an abstract description of the fields that might be included. It is a real form, that maybe has been filled out, different from all the other forms that have been filled out. That is an Object.

The fields on the form are filled in when an application is made. So in an Object, the attributes can have values. But in a Category, the attributes are descriptions of blanks on the form. So they don’t have actual data in them, they have data types. They describe the kind of data than can be put in that field when an application is actually made.

A Category “Person” might have the attribute “Name”, which has a String datatype. So in this example, The Category Person has an attribute “Name” with String as the datatype. If you create an object of that type, it also has an attribute called name (it has the same fields as the form defined by the Category), but that attribute has a value that is an actual string of text.

An object has the attributes of any Categories that it belongs to, and an object can belong to more than one category at the same time.

A Category serves as a data type in Blawx, so an attribute can hold data of any of the allowed datatypes, or any of the Categories that you have defined. For example, you can say that a Person has a Name, which is a String, and they have a friend, which is a Person.

Creating Categories

You create a category by putting a category declaration block in a fact block. A category declaration block can be found under the “Categories” drawer in the Toolbox.

When you drag a category declaration block onto the workspace, a corresponding category block is added under the “known categories” drawer of the toolbox. This block is used in blanks that require or allow a Category as a value.

Note that if you have two category declarations with the same name defined, Blawx will create two different known category blocks with the same text, using either of them has the same effect. So it is best practice not to have duplicates in category names in order to avoid confusion.

Adding Properties to a Category

Once you have declared a Category, you can use an category attribute block to give it one or more attributes. The category attribute block can be found in the “Categories” drawer of the toolbox, and looks like this:

To complete a category attribute block, you must provide the category that you are defining attributes for, and add attribute declaration blocks. The category attribute block comes with one attribute declaration block by default, but you can add more by dragging additional attribute declaration blocks from the “Categories” drawer of the toolbox.

For example, to say that “a person has a name and a best friend” you might set out an attribute declaration block like this:

Remember, all of this needs to be placed in a Fact block to work properly.

Category Equivalence

An object can have more than one category. One of the ways you can give an object more than one category is by stating that all objects of one category are also included in another category. For example, “all cats are mammals”.

In Blawx you can do this using the category equivalence block, which looks like this:

The category equivalence block requires two category blocks from the “Known Categories” drawer of the Toolbox. A complete category equivalence block would look like this:

Category equivalence works in one direction only. In this example, if you create an object, and give that object the category “Cat”, and then ask whether that object is in the category “Mammal”, the answer will be yes. If you create an object and give it only the category of “Mammal”, and then ask whether it is in the category “Cat”, the answer will be no.

Creating an Object

An object is created by using the object declaration block, which looks like this, and it just takes a name for the object.

When you drag an object declaration onto the Workspace, a corresponding Object Block appears in the “Known Objects” drawer of the Toolbox.

The object block for “Bob” can be used anywhere a block is expecting an or accepts an object as a value.

Giving an Object a Category

You give an object a category by using the object category block, which can be found in the “Objects” drawer of the Toolbox. It expects an object block and a category block. A completed object category block that says “Bob is a Person” looks like this.

Making Two Objects the Same Object

Sometimes your Blawx code will get data from more than one source, and each source may create its own versions of the same objects. In those cases, it can be useful to state that two objects are the same object. You can do that using the object equivalence block, which is found in the “Objects” drawer of the Toolbox, and which looks like this:

The object equivalence block takes two object blocks. To say that “Bob” and “Robert” are the same object, you could do this:

Note that unlike with the Category Equivalence, which goes in one direction only, object equivalence goes in both directions. If Bob is the same object as Robert, Robert is the same object as Bob. So if you set out Bob’s Middle name, and then say that Bob and Robert are the same object, asking for Bob’s middle name and asking for Robert’s middle name will both work.

No Comments

Add your comment