Syntactic examples


This file is intended to illustrate some commands or languages of WebKB-2. You can make WebKB-2 load this file and execute the commands in it, by entering the command
  run http://www.webkb.org/doc/webkb2SyntacticExamples.html;
in the "Add, remove or search statements" tool or simply click here.
Commands are in the courier font. They are enclosed within the XHTML marks <KR> and </KR> to permit WebKB-2 to distinguish them from regular text.

As in programs, the order of the following commands or group of commands is important. For example, a category must be added before being searched, used in a statement or removed. However, you can skip Section 2 if you just want to know how to add, remove or search statements in the KB.



Table of contents

  1. Some control commands
  2. Adding, removing and searching categories or links
    1. Adding categories
      1. Adding concept types
      2. Adding individuals
      3. Adding relation types
    2. Removing links/categories
    3. Modifying link destination/source
    4. Searching and comparing categories
  3. Adding, removing and searching statements
    1. Adding statements
      1. Existential statements
      2. Statements with contexts
      3. Statements with collections
      4. Universal statements
    2. Removing statements
    3. Searching and comparing statements



1. Some control commands

Normally, to add new categories to the KB, you would use category identifiers beginning by your user id (as in pm#physical_entity). Here, we assume you run this script in the name of the anonymous user "u" (hence, identifiers of created categories begin by "u#"). An associated consequence is that modifications made to the KB by the commands in this file will be roll-backed (or in other words, not committed) at the end of the execution. This permits this demonstation file to be re-executed without WebKB-2 to warn about already entered statements. To achieve the same effect for your files, (hence when creating with your id, not "u"), set the environment variable b012NoStorage to 1 (setting it to 2 would still imply that "u" is the default user). (When you have satisfied with the knowledge in one of your file, remove the command and run the file one more time for the knowledge to be commited in the KB).

b012NoStorage:= 1; 

Within commands on the ontology (Section 2), category identifiers must be used (not category names) and only WordNet categories can be written without user prefix (e.g. #time instead of wn#time). Within commands on statements (Section 3), you can use names instead of identifiers if you have used the command areNamesAllowed:= true;. You can also use identifiers without user prefix if you have used the command default creators: followed by a list of default user id (the order in the list is important: the first candidate category conform to the semantic constraints in the statement is taken). This list is also used for selecting the most relevant category when associating a category to a name.

areNamesAllowed:= true;  //ex: "use names;"
user u;     //the commands below are done in the name of the user "u"
//default creators: u pm; //it is generally not useful to specify default creators



2. Adding, removing and searching categories or links

Click here if you want to see the EBNF grammar of category/link related commands (i.e. the "FT" sub-language). Use the "Category search" tool for examples of the FT syntax. The generation of the update commands illustrated below is helped by the "Add or delete a link, category or name" tool.


2.1 Adding categories

2.1.1 Adding concept types

Before adding new categories to the shared KB, you must try to discover if similar categories already exist in order to reuse them or to link your new category to them (you would typically use a subtype link or an instance link). A category that is not connected to other categories has no meaning for WebKB-2: it is not retrievable and its use cannot be checked. It is therefore pretty useless. Conversely, the more links from your categories to other ones, the more retrievable and re-usable your knowledge (categories and statements) is, and the more useful your knowledge is for other users.

The "Category search" tool permits you to do lexical matching and semantic browsing to find existing categories with a meaning close to the one you have in mind. For example, if you want to find a category for "software companies", enter "software_company" in the "Category search" tool. If you do not have any answer, search for "company". If there is one or several answers, check the category annotations (descriptions in English) and the supertypes to find the appropriate category. If a category represents what you are thinking about, re-use it. If a category is a generalization of what you have in mind, look at its subtypes to see if one represents or generalizes the meaning of your ideal category. And so on. You may also check and explore other links than the subtype or instance links.

At the time of the creation of this document, there is no category with name "software_company" in the KB. The category #company/2 (from WordNet: the prefix "wn" is implicit for WordNet categories) appears to be the best generalization and none of its subtypes is more suitable. Therefore, adding a new category u#software_company as a subtype of #company/2 can be done:

u#software_company (^a company that creates or sell software^)
  < #company;  //the character '<' means "subtype of"

2.1.2 Adding individuals

Similarly, since no category for the software company "Netscape Pty Ltd" already exists, a representation of it can be added in the following way:

u#Netscape_Pty_Ltd__Netscape (^the Netscape company^)
  ^ u#software_company;  //the character '^' means "instance of"

The above declaration gives two names for the new category: "Netscape_Pty_Ltd" and "Netscape". The first is the key name: associated to the prefix "u#", it uniquely identifies the category, which could therefore also be refered as u#Netscape_Pty_Ltd. The Netscape browser is already represented in the KB:
#Netscape < #browser .  Both categories share a same name.
Note that individual names begin by a capital letter while most type names don't (at least in English). Please use English names and respect the correct spelling to ease the retrieval of your categories.

Something that may be specialized or has various occurrences or comes in different variants or versions should be represented as a type, not an individual. instance (click here for more details). For example, any doctrine, book, language, alphabetic character, code, diploma or recurring situation has to be represented as a type (at least in WebKB-2). Since there are many Netscape_4.7 versions, e.g. Netscape_4.7.1 and Netscape_4.7.2, but no sub-version of Netscape_4.7.2 (apparently), we can declare:

u#Netscape_4.7 (^version 4.7 of the Netscape browser^)
  < #Netscape,
  : u#Netscape_4.7.1 u#Netscape_4.7.2; //the character ':' means "instance"

If u#Netscape_4.7.2 does have versions and someone represents them by adding instance / subtype links from u#Netscape_4.7.2, the instance link from u#Netscape_4.7 to u#Netscape_4.7.2 should automatically be replaced by a subtype link   (not yet implemented).


2.1.3 Adding relation types

Using instance / subtype links for representing software versions ensures better retrieval and semantic checking (by WebKB-2) than using statements with relation types such as u#version or u#next_version. However, both representation can be used. Here is a declaration of the relation type u#next_version which should be used to connect a concept of type #software to another concept of type #software. This relation is a subtype of the relation type pm#inferior_to__less_than__superior.

u#next_version (#software,#software) (^connects a software version to the next^)
  < pm#inferior_to;

Here is an FCG illustrating its use: [u#Netscape_4.7.1, next_version: u#Netscape_4.7.2].
Note that relation types cannot have instance.



2.2 Removing links/categories

The next command deletes the instance link from u#Netscape_4.7 to u#Netscape_4.7.2. Only "u", the creator of this link, may perform this operation. Since u#Netscape_4.7.2 has no more link connected to it and belongs to "u", it is automatically deleted.

del u#Netscape_4.7 : u#Netscape_4.7.1;

The next command deletes the u#Netscape_4.7.1. This is permitted by WebKB-2 since "u" has created this category and all the links connected to it. If one of these links had been created by another user, say "u2", u#Netscape_4.7.1 would have become u2#Netscape_4.7.1 (not yet implemented; at present, the category would not be removed, only the links belonging to "u" would be removed).

del u#Netscape_4.7.2;



2.3 Modifying link destination/source

The next command replaces u#Netscape_4.7 by u#Netscape_4.8 as destination of a subtype link from #Netscape. This operation may only be performed by the creator of the link, i.e. "u". Since u#Netscape_4.8 has no more link connected to it, it is removed.

mod (#Netscape > u#Netscape_4.7) (#Netscape > u#Netscape_4.8);

Similarly, the source of a link may be modified. The previous command is equivalent to:
mod (u#Netscape_4.7 < #Netscape) (u#Netscape_4.8 < #Netscape);



2.4 Searching and comparing categories

The best way to search or compare categories is to use the "Category search" tool and the
"Compare categories" tool (or the associated CGI scripts from a program).
Category comparison using test expressions (as in
if (u#Netscape_4.8 < #Netscape) print "yes"; else print "no";)  is not yet implemented.
The command "?" may be used to print the direct links from a given category and its indirect supertypes.
For example:   ? #Netscape ;




3. Adding, removing and searching statements

In the examples below, we are using the FCG language for writing statements. To ease their interpretation, a translation in English (E) and Formalized English (FE) is often given. Click here if you want to see the EBNF grammars of FCG and FE. When there was no ambiguity, we have used category names intead of identifiers (we have warned WebKB-2 with the command "areNamesAllowed:= true;" in Section 1). When a statement is written without a command name before it, it is added (asserted) into the KB when it is interpreted by WebKB-2. The generation of statement related commands is helped by the "Add, remove or search statement" tool.

Here is the declaration of categories needed by the example statements.

#woman: u#Mary;
#adult_man: u#Joe;
#cat : u#Tom;


3.1 Adding statements

3.1.1 Simple existential statements


//E:  Mary likes herself and the #cat named "Tommy".
//FE: There is a liking which has for agent u#Mary,
//         for object u#Mary and for object the #cat that has for name "Tommy".
[u#Mary, agent of: (a liking, object: u#Mary, object: (the #cat, name: "Tommy"))];

//E:  A cat "c" that is not Tom is on a mat.
//FE: A cat *c that is different_from u#Tom and that is on a #mat.
     [a #cat *c != u#Tom, on: a #mat];


//E:  A certain person "p" created the home page http://www.w3.org/~lassila.
//FE: A #person *p is the creator of the pm#WWW_home_page http://www.w3.org/~lassila.
     [a #person *p, creator of: the pm#WWW_home_page http://www.w3.org/~lassila];

//E:  This person ("p") is named Ora Lassila.
//FE: *p has for name "Ora Lassila".
     [*p, name: "Ora Lassila"];

3.1.2 Statements with contexts

Contexts permits to indicate temporal or spatial aspects of a situation, to represent statements on statements, and even to name it by associating an individual to the statement as in the 1st next example. The individual identifier must not yet exist and must begin by the creator identifier (here "u"). If no individual is provided, WebKB-2 creates an individual; you will see it if the statement is printed (unless you have asked for the original text of the statement to be used when printing the statement).


//E:  Mary does not own a car.
//FE: !`u#Mary is owner of a #car'.
     [u#MaryHasNoCar ![u#Mary, owner of: a #car]];

//E:  Joe believes that Mary now likes him (in 1999) and that before she did not.
//FE: u#Joe is believer of `*s `u#Mary is liking u#Joe time 1999'
//    and is believer of `!`*s' before_time 1999'.
     [u#Joe, believer of: [*s [u#Mary, agent of: (a liking, object: u#Joe)], time: 1999],
          believer of: [![*s], before_time: 1999] ];

3.1.3 Statements with collections

//E:  u#Mary, u#Joe and another man collectively authored a resolution.
//FE: Together *these_persons {u#Mary,u#Joe,an #adult_man} are author of a #resolution.
     [together *these_persons {u#Mary,u#Joe,an #adult_man}, author of: a #resolution];

//E:  These persons are each author of a resolution.
//FE: *these_persons are author of a #resolution.
     [*these_persons (^each of them^), author of: a #resolution];

//E:  u#Joe ran between 14 min and 15 min.
//FE: u#Joe is agent of some #running with duration 14 to 15 min.
     [u#Joe, agent of: (some #running, time: 14 to 15 min)];

//E:  u#Joe ran between 14hrs and 15hrs (2pm to 3pm).
//FE: u#Joe is agent of some #running with time from 14:00 to 15:00.
     [u#Joe, agent of: (some #running, time: from 14:00 to 15:00)];


3.1.4 Universal statements

//E:  Every person that can write, can read.
//FE: Every [#person that can be agent of a #writing] can be agent of a #reading.
     [every (#person, can be agent of: a #writing), can be agent of: a #reading];

//E:  At least 2 % of persons like most of cats.
//FE: At least 2 % of #person are liking most of #cat.
     [at least 2 % of #person, agent of: (a liking, object: most of #cat)];



3.2 Removing statements

To remove a statement, you need to have created it and to know the identifier of the individual that represents the statement (cf. Section 3.1.2).

delGraph u#MaryHasNoCar;

The command delGraphs is not yet implemented. It will permit you to remove all your statements from the KB.



3.3 Searching and comparing statements

As for categories, statement comparison within test expressions is not yet implemented.

Statements may be searched via the commands spec and ?.
Click here for details on the "?" command and planned extensions to the current implementation.


spec [a #person, agent of: (a liking, object: a #person)];
? [a #resolution];