Question about cross-linking and creation of instances [message #1133248] |
Fri, 11 October 2013 18:39 |
Ricardo \\\"CaWal\\\" Cacheta Waldemarin Messages: 29 Registered: January 2013 |
Junior Member |
|
|
Hello!
I'm facing some problems about how to write grammars using Xtext. I'm building an ontology editor using EMF, OCL, GMF and Xtext, but I'm stucked in the grammar definition to (de-)serialize the ontologies as text: I don't know how to map my metamodel to the file format I need to use.
In order to better understand the problem and the grammar language I created a small toy example with a toy domain metamodel that represents the main issue I want to address. You can see this metamodel in the next figure.
The approach is quite simple (and I think you are familiar to the main idea): An ontology has terms and relationships. Terms represent entities of a domain and can be seen as nodes of a graph. Relationships represents directed relations that hold between two terms and can be seen as arcs between two nodes of a graph, linking one term (source) to another (target). Terms and Relationships has an reference called 'ontology' that points to the ontology that are their container. I have some constraints and derivations written (and working) using OCL, but I think structural features are more important in the example.
In the next figure I show a simple example with two terms and a relationship. Even I didn't used arrow decorations in the example, let's assume that the relationship points from termA to termB and it's called "annotates" (so it can be said "termA annotates termB").
Please, note that I don't want the name field of the relationship as an identificator to that relationship instance, but only as a classifier of the relationship type (thus, allowing more than one relationship to have the same name). Also, the three instances are contained by the ontology, that is the entry rule to my Xtext grammar and is symbolized by the canvas.
The main problem I'm facing is that I need to serialize the instances in a similar way that the OBO File Format does (www.geneontology.org/GO.format.obo-1_2.shtml). For instance, a ontology is serialized as a set of stanzas that begin with a label folowed by a pair of tag-value pairs. Each stanza defines a term that is identified by the id tag (the first pair). Also, the definition of a term can be spreaded into several stanzas. In this case, every stanza that is defining the same term begin with the same id pair.
I want to serialize the example ontology as...
name: theNameOfTheOntology
[Term]
id: idOfTermA
name: termA
relationship: annotates idOfTermB
[Term]
id: idOfTermB
name: termB
As you can see, the relationship's name is used within an stanza that describes a term, but during the parsing I have to return the relationship instance to the ontology instance that contains it. Also, there's no explicit identificator to each relationship instance, so I don't know if i need to add it or can create in parse time (and make it transient).
I'm trying to write a grammar to parse and serialize this format, but I don't know how exactly I can use crosslinks. I don't even know if it's possible to do that. Is it possible to write a grammar to this example directly with Xtext? Does anyone have a clue how I can address this problem?
Bellow I show how I'm trying to do it. Maybe it helps. Thank you in advance and sorry for the verbosity!
grammar toyOntology.ToyOntologyDSL with org.eclipse.xtext.common.Terminals
import "platform:/resource/toyOntology/model/toyOntology.ecore"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Ontology returns Ontology:
{Ontology}
'name:' name=EString
(terms+=Term)*;
Term returns Term:
{Term}
'[Term]'
'id:' id=EString
(('name:' name=EString) | 'relationship:' ***parse the relationship in any way***))*;
EString returns ecore::EString:
STRING | ID;
|
|
|
Re: Question about cross-linking and creation of instances [message #1133269 is a reply to message #1133248] |
Fri, 11 October 2013 19:01 |
|
Hello Ricardo,
i am not sure if i get your question.
the syntax for cross references is
which is short for
=> an ID will be parsed. if you want to change it:
Whatever: ref=[Term| EString]
please note: if you want to refer by id you will have to adapt IQualifiedNameProvider not to use the name attribute
the point
Quote:As you can see, the relationship's name is used within an stanza that describes a term, but during the parsing I have to return the relationship instance to the ontology instance that contains it. Also, there's no explicit identificator to each relationship instance, so I don't know if i need to add it or can create in parse time (and make it transient).
i dont really understand your point. the sample model looks like this can work without any problem
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.02738 seconds