Projects



Changes between Initial Version and Version 1 of Paose/Documentation/Howto-CD


Ignore:
Timestamp:
Nov 1, 2010, 10:37:33 AM (14 years ago)
Author:
Lawrence Cabac
Comment:

copied concept diagrams from tgi15 trac

Legend:

Unmodified
Added
Removed
Modified
  • Paose/Documentation/Howto-CD

    v1 v1  
     1= !HowTo: Concept Diagrams and Ontology Generation with FS Concepts =
     2
     3This document explains the purpose and handling of the ''Concept Daigrams'' provided by the plugins: ''Feature Structures'' (Renew plugin FS) and  ''Feature
     4Structure Ontology Generator'' (Mulan plugin
     5''FSOntologyGenerator'').
     6
     7== (1) Introduction ==
     8
     9The FSOntologyGenerator plugin is used to build the ontology for a
     10Mulan project from simple Renew drawings. Hereby, it replaces the
     11Protégé-based !OntologyGenerator plugin. The generated classes then
     12encapsulate a FIPA-compatible ontology with convenient constructors
     13and accessors and the build-in functionality to parse or generate ACL
     14message strings with SL representations for the concepts.
     15
     16As a reference, the Mulan plugin FSOntologyTestPlugin is a complete
     17example project showing how the generator could be used.
     18
     19== (2) Embedment in the PAOSE Development Process ==
     20
     21The following figure shows how the !FSOntologyGenerator plugin fits
     22into the overall PAOSE development process.
     23
     24[[Image(paose-detailed-fsonto.png)]]
     25
     26There are two development areas where the ontology plays a role:
     27  * The ontology design, which is done using concept diagrams
     28  * The implementation of nets which make use of the generated
     29  classes, especially protocol nets.
     30
     31== (3) Creating Ontology Diagrams ==
     32[[Image(example_prodstorecons.png)]]
     33
     34An ontology is defined by a concept diagrams, which is very similar to
     35UML class diagrams. They are simply stored as .rnw files.
     36
     37=== (3.1) XFS Toolbar components ===
     38
     39Ontology diagrams are built using the Renew XFS toolbar (you get it
     40through Simulation -> Formalisms -> XFS Net Compiler).
     41
     42[[Image(xfs_toolbar.png)]]
     43
     44Actually, just
     45two of its tools are really needed:
     46  * Concept Tool: Used to add new concepts to the
     47  diagram. After clicking on the drawing pane, you get a text box
     48  where you can enter the concept name and its slots (if it has some)
     49  * Disjunctive Is-A Tool: Relates a concept to a
     50  superconcept. Slots will be inherited.
     51
     52'''Don't use the other Is-A tool''', as its semantics cannot
     53be translated to class hierarchies, thus edges drawn with this will
     54yield a compiler error.
     55
     56=== (3.2) Declaring Slots ===
     57
     58Usually, slot definitions for a concept are put into the concept box
     59after the concept name (be sure to put two line breaks in
     60between). The syntax is name:type, where type may be any Java type
     61(primitive or class) or any concept name (in the same ontology or one
     62that is imported or accessed (see 3.6). The type may optionally be
     63followed by a Kleene star (*) to indicate a multi-valued slot
     64which will be represented as a list of values.
     65
     66Example:
     67{{{
     68my-concept
     69
     70one-slot:int
     71another-slot:some-concept
     72all-strings:String*
     73}}}
     74
     75This defines a concept named my-concept with three slots:
     76  * one-slot has the type int
     77  * another-slot with type some-concept
     78  * all-strings with the type "list of strings"
     79
     80Optionally, the feature tool could be used for slot declarations,
     81instead, similar to UML diagram - although the "inline" way seems more
     82readable and is therefore recommended.
     83
     84=== (3.3) Documenting Concepts and Slots ===
     85
     86For documentation of the generated classes, Javadoc-style comments may
     87be written before the concept (the comment should also precede a
     88stereotype if present - see 3.4) as well as before each slot.
     89
     90Example:
     91{{{
     92/** This is the doc for my concept. */
     93my-concept
     94
     95/** Doc for one slot. */
     96one-slot:int
     97another-slot:some-concept
     98/** Doc for all strings */
     99all-strings:string*
     100}}}
     101
     102The slot called "another-slot" has no comment in this example.
     103
     104If you get any compilation errors with documented concepts, check the
     105syntax: For example, currently, there must be a line break directly
     106after "*/".
     107
     108=== (3.4) Abstract and Concrete Classes ===
     109
     110Due to Capa restrictions, all concepts that are superconcepts have to
     111be abstract (the generated class cannot be instantiated). The
     112generator will therefore treat all concepts with subconcepts as
     113abstract and those without subconcepts (in the same ontology) as
     114concrete. For forcing a concept to be abstract, the <<abstract>>
     115stereotype is used, for example:
     116{{{
     117<<abstract>>
     118my-concept
     119
     120my-slot:int
     121}}}
     122
     123This is useful for cross-ontology references (see 3.5).
     124
     125=== (3.5) Cross-Ontology-References ===
     126
     127It is possible to inherit from concepts that are in other ontologies
     128by drawing a "reference concept" named
     129"referencedOntology::conceptName" (there is no need to repeat the
     130slots or stereotype in the reference) and inherit from this "reference
     131concept". There must be an access declaration for the referenced
     132ontology (see 3.6).
     133
     134When inheriting from a foreign concept that has no "local subconcepts"
     135(i.e. in the same ontology), the concept must be declared abstract
     136(see 3.4).
     137
     138=== (3.6) The Declaration Node ===
     139
     140The declaration node holds ontology-level information like package,
     141imports and accesses.
     142
     143==== Package ====
     144
     145The first line must declare the Java package of the ontology, just
     146like in a Java source file.
     147
     148==== Access Declarations ====
     149
     150The next (zero to n) lines can be access declarations for referencing
     151external ontologies. Be sure to configure the ant task right (see 4.2)
     152so that the net holding the referenced ontology can be found. An
     153access declaration consists of the "access" keyword as well as the
     154name of the referenced ontology (but without the package). After
     155accessing an ontology, all of its concepts can be used as slot types
     156and for inheritence (see 3.5).
     157
     158==== Import Declarations ====
     159
     160Following the access declarations, there can be any number of normal
     161java imports. All imported classes can be used as slot types (but not
     162for inheritence).
     163
     164
     165'''Be sure to put package, accesses and imports in the order given
     166here''' - otherwise a parser error will occur.
     167
     168Example:
     169{{{
     170package de.renew.agent.settler.ontology;
     171access Basic;
     172access GameConcepts;
     173import java.net.URI;
     174import java.util.*;
     175}}}
     176
     177== (4) Configuration of the Ant Target ==
     178
     179General information about ant can be found at
     180http://ant.apache.org/manual/. The basics are axplained pretty well at
     181http://ant.apache.org/manual/using.html.
     182
     183To call the ontology generator from ant, there is the createfsontology
     184task.
     185
     186=== (4.1) Basic Functionality ===
     187
     188In the simple case, it takes a destination directory as (mandatory)
     189parameter. A fileset of ontology-sns-files belongs in the body - all
     190those ontologies will be generated.
     191
     192Simple example:
     193{{{
     194  <createfsontology destdir="build/gensrc">
     195    <fileset dir="build/classes/ontology">
     196      <include name="*.sns"/>
     197    </fileset>
     198  </createfsontology>
     199}}}
     200
     201Note that using explicit paths like here is considered bad style -
     202usually, it is a better idea to use properties for directory
     203references, which will be done in the following examples.
     204
     205=== (4.2) The Netpath ===
     206
     207The netpath is needed in order to find ontologies referenced by access
     208declarations (see 3.6). All ontologies in the body-fileset will
     209automatically be added to the netpath, so it is no problem to access
     210one generated ontology from another.
     211
     212But sometimes, there are ontologies in other plugins or target folders
     213that we would like to refererence. In this case, we need to use a
     214reference to a netpath:
     215{{{
     216  <createfsontology destdir="${dir.build.gensrc}" netpathref="ref.ontology.netpath">
     217    <fileset dir="${dir.build.classes}">
     218      <include name="ontology/ProdStoreCons.sns"/>
     219    </fileset>
     220  </createfsontology>           
     221}}}
     222
     223Now, all references from the !ProdStoreCons ontology to ontologies
     224found in ref.ontology.netpath will be correctly resolved. The netpath
     225could have been configured like this:
     226{{{
     227  <path id="ref.ontology.netpath">           
     228    <pathelement location="${dir.build.classes}/ontology"/>
     229  </path>
     230}}}
     231
     232=== (4.3) Where the Shadows Come From ===
     233
     234Shadow nets are usually built from the .rnw source using the createsns
     235task. You should use a seperate targets for building the ontology sns
     236files and the reference net sns files, instead of trying to do all in
     237the same target. This is because for syntax check, the createsns task
     238should be set up to compile the nets. Then, we should use the
     239XFSNetCompiler instead of the !JavaNetCompiler. Also, there would be
     240cyclic references: The ontology generator needs the sns target, while
     241the reference nets need the generated ontologies to compile.
     242
     243The ontology sns target might look like this:
     244{{{
     245<target name="ontology.sns.app" depends="init">
     246  <path id="ref.classpath.sns">
     247    <path refid="ref.classpath"/>
     248    <pathelement location="${dir.build.classes}"/>
     249  </path>
     250
     251  <!-- creates separate sns for each rnw -->
     252  <createsns destdir="${dir.build.classes}"
     253             classpathref="ref.classpath.sns"
     254             compilername="de.renew.formalism.fsnet.XFSNetCompiler"
     255             compile="true">
     256    <fileset dir="${dir.src}">         
     257      <include name="ontology/**/*.rnw"/>
     258    </fileset>
     259  </createsns>
     260</target>
     261}}}
     262
     263=== (4.4) Full example from FSOntologyTestPlugin ===
     264
     265This example shows the complete ontology.app target from
     266FSOntologyTestPlugin. There are two ontologies: Basic and
     267!ProdStoreCons. They will be built in two phases for demonstration,
     268although they are in the same plugin and folder - usually, of course,
     269one would just do both at once.
     270{{{     
     271<target name="ontology.app" depends="init.mulantasks,ontology.sns.app">
     272  <!-- Build the ontology in two phases just to demonstrate how it works -->
     273  <!-- First, just the "Basic" ontology, no netpath is needed here -->
     274  <createfsontology destdir="${dir.build.gensrc}">
     275    <fileset dir="${dir.build.classes}">
     276      <include name="ontology/Basic.sns"/>
     277    </fileset>
     278  </createfsontology>
     279
     280  <!-- Configure the netpath to look for referenced ontology sns's -->
     281  <path id="ref.ontology.netpath">           
     282    <pathelement location="${dir.build.classes}/ontology"/>
     283  </path>
     284
     285  <!-- Second, the ProdStoreCons ontology which references Basic.
     286       As Basic is not in the fileset, we need the netpath here -->
     287  <createfsontology destdir="${dir.build.gensrc}" netpathref="ref.ontology.netpath">
     288    <fileset dir="${dir.build.classes}">
     289      <include name="ontology/ProdStoreCons.sns"/>
     290    </fileset>
     291  </createfsontology>           
     292</target>
     293}}}
     294
     295== (5) About the Generated Classes ==
     296
     297For each ontology concept, a Java class is being generated. Abstract/concrete concepts will have
     298abstract/concrete classes, respectively.
     299
     300=== (5.1) Class Hierarchy ===
     301The generated class hierarchy normaly reflects the concept hierarchy -
     302with a few exceptions:
     303
     304  * The superconcept of all concepts is "concept", theoretically - but this has no
     305    semantic meaning, so a concept with this name will just be ignored
     306    for the generation process.
     307  * Concepts with name "agent-action" or "predicate" will not be
     308    generated, either, but concepts inheriting from them will be
     309    regarded agent actions or predicate, respectively. Classes
     310    generated from agent actions and predicates will have special
     311    methods (see 5.5).
     312  * Concepts directly inheriting from "predicate" are mapped to
     313    classes inheriting from GenericVT, while all other concepts with
     314    no superconcepts besides "concept" or "agent action" inherit from
     315    GenericKVT. This is due to FIPA specifications, where predicated
     316    are regarded as value-tuples, while other concepts are usually
     317    key-value-tuples.
     318  * Sometimes people feel happy to draw the concept agent-identifier -
     319    although the corresponding class is already implemented in
     320    Capa. Therefore, this concept will also be ignore by the generator.
     321
     322=== (5.1) Automatic Name Conversion ===
     323
     324All concept names, slot types and slot names will be converted to Java
     325conventions using the following two rules:
     326   * Hyphens will be replaced by camelCase.
     327   * Concept names and non-primitive slot types will be capitalized to
     328   yield legal class names.
     329
     330For example, the concept defined by
     331{{{
     332my-nice-concept
     333
     334first-slot:int
     335second-slot:String
     336third-slot:neighbour-concept
     337}}}
     338
     339generates a class of name !MyNiceConcept with three slots:
     340 * firstSlot of type int
     341 * secondSlot of type String
     342 * thirdSlot of type !NeighbourConcept
     343
     344=== (5.2) Constructors ===
     345
     346Concrete classes have two visible constructors:
     347 * A basic constructor without any parameters - all slots will be
     348 null unless explicitly set later
     349 * A conveniance constructor with a parameter for each
     350 slot. If null is given instead of any parameter, the corresponding
     351 slot will not be set. Multi-valued slots have parameter type
     352 VTSequence. Primitive types slots have the boxed type as parameter
     353 (e.g. int has Integer), so null can also be used here.
     354
     355Also, the static methods fromString and fromAclMessage(for predicates,
     356this is called predicateFromAclMessage) are generated, which take a string
     357in SL1 and Acl format, respectively, which will be parsed. They then return an instance of the
     358concept class. (It was not possible to make this a constructor, as a
     359concept with exactly one slot of type String already has a conveniance
     360constructor with this signature.)
     361
     362=== (5.3) Accessors for Simple Slots ===
     363
     364Simple (that is, not multi-valued) slots have simply a getter and a
     365setter using the types given in the slot definition. This also holds
     366for primitive Java types like int, although slots of this kind are
     367internally stored using the boxed types - the conversion is done
     368automatically by the accessors.
     369
     370=== (5.4) Accessors for Multi-Valued Slots ===
     371
     372For multi-valued slots or list slots, several methods will be
     373generated. For example, the slot defined by
     374{{{
     375village:String*
     376}}}
     377produces the following methods:
     378  * void setVillage(VTSequence vals)
     379    Sets the slot to the given list.
     380  * VTSequence getAllVillage()
     381    Gets all villages stored in the list slot.
     382  * Iterator getAllVillageAsIterator()
     383    Gives an iterator over all villages.
     384  * void addVillage(String val)
     385    Adds a village to the list.
     386  * void removeVillage(String val)
     387    Removes the given village from the list.
     388  * void addAllVillage(VTSequence vals)
     389    Appends the given list of villages.
     390  * void removeAllVillage(VTSequence vals)
     391    Removes all villages in the given list.
     392
     393Automatic boxing is also done for list slots, so a slot of type int*
     394will have add- and remove-methods with type int as parameter.   
     395
     396=== (5.5) Other Generated Methods ===
     397
     398As mentioned in 5.1, agent actions and predicates will get a few extra
     399methods generated.
     400
     401Methods for agent actions:
     402  * toActionRequest(!AgentIdentifier receiver)
     403    Generates an Acl message which asks the receiver to perform this
     404    action.
     405  * Depricated:
     406    * toAclMessage(!AgentIdentifier receiver)
     407      Alias for toActionRequest.
     408    * toAclInform(!AgentIdentifier receiver)
     409      Wraps an inform around the action. This construct should rather
     410      be avoided, as it is semantically unclear who is performing the
     411      action.
     412
     413Methods for predicates:
     414  * toSimpleInform(!AgentIdentifier receiver)
     415    Wraps an inform message around this predicate.
     416  * toQueryIf(!AgentIdentifier receiver)
     417    Wraps a query-if message around this predicate.