EMF Resource to OWL

72 views
Skip to first unread message

jungwacht

unread,
Nov 18, 2010, 8:48:28 AM11/18/10
to emftriple-discuss
Hi, I have an XML structure and many instances of it. I thought I
could load it to a EMF resource and hand it over to EMF4SW.
Here is what I'm trying to do:
1. I created a XSD schema of my xml files
2. I generated the java code with EMF, so I have some nice POJOs
3. I load my XML files to the POJOs with EMF
4. transform from ecore (Resource) to OWL

My list of resources is empty:
List<Resource> owlModels = new
Ecore2OWLResources(OWLFormats.TURTLE).apply(resource);

Any idea?
Thanks!
borobudur

Guillaume Hillairet

unread,
Nov 18, 2010, 9:11:37 AM11/18/10
to emftriple-discuss
Hi,

In this case, you don't use the Ecore2OWL transformation, but you
should use the
RDFIzer [1] (wiki may be not up to date).
So your code should look like this:

RDFIzer rdfizer = new RDFIzer(YourMetamodelPackage.eINSTANCE);
Resource model =
resourceSet.createResource(URI.createURI("model.xmi")); // xml model
model.load(null);

Resource rdf = rdfizer.toRdf(model, RDFFormats.TURTLE_FORMAT);
rdf.setURI(URI.createURI("model.ttl"));
rdf.save(null);

At a result, you will have an RDF file containing the triples
generated from your xml file. Structure of
the RDF resources is derived from the metamodel you got from XSD and
so the generated POJOs.

[1] http://code.google.com/a/eclipselabs.org/p/emftriple/wiki/RDFIzerGuide

jungwacht

unread,
Nov 19, 2010, 4:04:29 AM11/19/10
to emftriple-discuss
Thanks for the quick answer.
I tried this but I get an exception that there is an id missing in the
root element:
Caused by: java.lang.IllegalArgumentException: Object of type
org.eclipse.emf.ecore.impl.EClassImpl@1d38b87 (name: DocumentRoot)
(instanceClassName: null) (abstract: false, interface: false) must
declare an Id attribute
at com.emf4sw.rdfizer.atl.IDGenerator.processId(IDGenerator.java:84)
at com.emf4sw.rdfizer.atl.IDGenerator.getId(IDGenerator.java:67)
at com.emf4sw.rdfizer.atl.ETripleLibExtension
$3.exec(ETripleLibExtension.java:80)
at com.emf4sw.rdfizer.atl.ETripleLibExtension
$3.exec(ETripleLibExtension.java:1)
at
org.eclipse.m2m.atl.engine.emfvm.ASMOperation.exec(ASMOperation.java:
391)
... 35 more

The DocumentRoot object is generated from EMF. Under this element I
can find my root from the XML-file.
Any idea?

Guillaume Hillairet

unread,
Nov 19, 2010, 6:21:52 AM11/19/10
to emftriple-discuss
Hi,

You need to declare the ids (using annotations) for each class of your
metamodel . You can check this
example [1].

Here I use Emfatic ti modify my metamodel.
The @Id annotation must be use on an attribute, that you know can
uniquely identify each objects instance of the class. The base
property must be set, and defines the
base namespace that will be use to generate object URIs (attribute
value is append to the base property).

abstract class Project {
@Id(base="http://www.example.com/projects/")
attr String name;
attr String description;
ref Employee teamLeader;
}

Note that all subclasses that don't define their own @Id will use
superclass @Id.

class SmallProject extends Project {
}

In the case you have no unique identifier in a class, you can use the
@GeneratedId annotation. This one will generate a URI by appending a
value to a base namespace. In your
case, this kind of annotation can be put on the DocumentRoot class.

@GeneratedId(base="http://www.example.com/dates/")
class EmploymentPeriod {
attr EDate startDate;
attr EDate endDate;
}

[1]
http://code.google.com/a/eclipselabs.org/p/emftriple/source/browse/trunk/examples/com.emf4sw.rdfizer.examples/src/resources/employee.emf

jungwacht

unread,
Nov 19, 2010, 7:28:03 AM11/19/10
to emftriple-discuss
Hi Guillaume, thanks again for your help.

I saw the annotation issue but I didn't find the location where to
place the annotations.
Your example is an *.emf file. I don't have such a file.
In the generated java classes, as much I understand the code, I can't
place the annotation directlly to the class attributes.

Can you tell me how to get the emf-file?
Thanks!


On 19 Nov., 12:21, Guillaume Hillairet <g.hillai...@gmail.com> wrote:
> Hi,
>
> [1]http://code.google.com/a/eclipselabs.org/p/emftriple/source/browse/tr...

jungwacht

unread,
Nov 19, 2010, 7:34:50 AM11/19/10
to emftriple-discuss
Hi Guillaume, thanks again for your help.

I saw the annotation issue but I didn't find the location where to
place the annotations.
Your example is an *.emf file. I don't have such a file.
In the generated java classes, as much I understand the code, I can't
place the annotation directlly to the class attributes.

Can you tell me how to get the emf-file?
Thanks!


On 19 Nov., 12:21, Guillaume Hillairet <g.hillai...@gmail.com> wrote:
> Hi,
>
> [1]http://code.google.com/a/eclipselabs.org/p/emftriple/source/browse/tr...

Guillaume Hillairet

unread,
Nov 19, 2010, 7:39:15 AM11/19/10
to emftriple-discuss
In the examples I'm using Emfatic to define my metamodels. You can
download it from here http://scharf.gr/eclipse/emfatic/download/.
Once you've downloaded it, right click on your ecore file and select
generate emfatic file. Then a .emf file will be generated. Once you
added
the annotations, right click on the .emf file and select generate
ecore model. It will replace the ecore file with a new one that
contain the annotations.
You can also create annotations with the basic ecore editor. See the
employee.ecore model in the rdfizer examples.

jungwacht

unread,
Nov 19, 2010, 9:05:16 AM11/19/10
to emftriple-discuss
I'm lost! I added the following two annotations but I still have the
same exception after regenerating:
@ExtendedMetaData(name="", kind="mixed")
class DocumentRoot {

@GeneratedId(base="http://eu.plugit/cmonxml")
@DataProperty(uri="http://eu.plugit/cmonxml#name")
@ExtendedMetaData(kind="element", name="xml-fragment",
namespace="##targetNamespace")
volatile transient derived !resolve val XmlFragment[0..?]
xmlFragment;
...


On 19 Nov., 13:39, Guillaume Hillairet <g.hillai...@gmail.com> wrote:
> In the examples I'm using Emfatic to define my metamodels. You can
> download it from herehttp://scharf.gr/eclipse/emfatic/download/.

Guillaume Hillairet

unread,
Nov 19, 2010, 9:12:52 AM11/19/10
to emftriple-discuss
That is just because the @GeneratedId annotation has to be put on the
class, not on the attribute, like that:

@GeneratedId(base="http://eu.plugit/cmonxml/") // Note that the
namespace must end with / or # in order to make a well formed URI.
@ExtendedMetaData(name="", kind="mixed")
class DocumentRoot {
...

Note also that you don't need to put other kinds of annotations,
except if you want to rename properties or classes.

jungwacht

unread,
Nov 19, 2010, 10:59:38 AM11/19/10
to emftriple-discuss
It works now. Many thanks!!

Last question (I hope): My XSD is actually the owl classes and the XML
are the instances of it.
How can I melt both together in one ontology?

jungwacht

unread,
Nov 19, 2010, 10:31:22 AM11/19/10
to emftriple-discuss
I did it! Many thanks!!

On 19 Nov., 15:12, Guillaume Hillairet <g.hillai...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages