ghillairet / emftriple

EMF Binding for RDF
25 stars 8 forks source link

IllegalArgumentException when trying to store a model #11

Open jannvck opened 9 years ago

jannvck commented 9 years ago

I have a rather complex Ecore model which I'm trying to serialize to RDF with emftriple. The storage method is according to the one found in the the README. Upon calling resource.getContents().add(model); I get the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: The datatype 'EFeatureMapEntry' is not a valid classifier at org.eclipse.emf.ecore.impl.EcoreFactoryImpl.convertToString(EcoreFactoryImpl.java:221) at org.eclipse.emf.ecore.util.EcoreUtil.convertToString(EcoreUtil.java:3495) at org.eclipselabs.emftriple.sesame.map.Extensions.toLiteral(Extensions.java:48) at org.eclipselabs.emftriple.sesame.map.Extensions.add(Extensions.java:58) at org.eclipselabs.emftriple.sesame.map.Serializer$5.apply(Serializer.java:114) at org.eclipse.xtext.xbase.lib.IteratorExtensions.forEach(IteratorExtensions.java:362) at org.eclipse.xtext.xbase.lib.IterableExtensions.forEach(IterableExtensions.java:331) at org.eclipselabs.emftriple.sesame.map.Serializer.serialize(Serializer.java:117) at org.eclipselabs.emftriple.sesame.map.Serializer.access$0(Serializer.java:86) at org.eclipselabs.emftriple.sesame.map.Serializer$3.apply(Serializer.java:56) at org.eclipselabs.emftriple.sesame.map.Serializer$3.apply(Serializer.java:1) at org.eclipse.xtext.xbase.lib.IteratorExtensions.forEach(IteratorExtensions.java:362) at org.eclipse.xtext.xbase.lib.IterableExtensions.forEach(IterableExtensions.java:331) at org.eclipselabs.emftriple.sesame.map.Serializer.to(Serializer.java:59) at org.eclipselabs.emftriple.sesame.map.Serializer.serializeOne(Serializer.java:173) at org.eclipselabs.emftriple.sesame.map.Serializer.serialize(Serializer.java:160) at org.eclipselabs.emftriple.sesame.map.Serializer.access$1(Serializer.java:127) at org.eclipselabs.emftriple.sesame.map.Serializer$4.apply(Serializer.java:64) at org.eclipselabs.emftriple.sesame.map.Serializer$4.apply(Serializer.java:1) at org.eclipse.xtext.xbase.lib.IteratorExtensions.forEach(IteratorExtensions.java:362) at org.eclipse.xtext.xbase.lib.IterableExtensions.forEach(IterableExtensions.java:331) at org.eclipselabs.emftriple.sesame.map.Serializer.to(Serializer.java:67) at org.eclipselabs.emftriple.sesame.map.Serializer$2.apply(Serializer.java:39) at org.eclipselabs.emftriple.sesame.map.Serializer$2.apply(Serializer.java:1) at org.eclipse.xtext.xbase.lib.IteratorExtensions.forEach(IteratorExtensions.java:362) at org.eclipse.xtext.xbase.lib.IterableExtensions.forEach(IterableExtensions.java:331) at org.eclipselabs.emftriple.sesame.map.Serializer.to(Serializer.java:42) at org.eclipselabs.emftriple.sesame.map.EObjectMapper.to(EObjectMapper.java:37) at org.eclipselabs.emftriple.sesame.map.EObjectMapper.to(EObjectMapper.java:19) at org.eclipselabs.emftriple.sesame.resource.RDFResource.doSave(RDFResource.java:60) at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430) at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:999) at Model2RDF.saveModel(Model2RDF.java:76) at Model2RDF.main(Model2RDF.java:39)

jannvck commented 9 years ago

Serialization to XMI and XML works without modification.

jannvck commented 9 years ago

I am not sure whether this issue is directly related to emftriple, see https://www.eclipse.org/forums/index.php/t/128219/

But as I said, serialization to XMI and XML works.

ghillairet commented 9 years ago

More likely because not all EMF features are supported in emftriple, FeatureMaps may be one that are not.

jannvck commented 9 years ago

Thank you for your reply.

I might implement this. Maybe you can point me to the right direction, where to start?

ghillairet commented 9 years ago

During serialization, check that an attribute is a feature map, and then handle that case, maybe like it is done there https://github.com/ghillairet/emfjson/blob/master/emfjson-jackson/src/main/java/org/emfjson/jackson/databind/ser/EObjectSerializer.java#L124

jannvck commented 9 years ago

Thank you for that hint. BTW the feature map is treated as an EReference.

jannvck commented 9 years ago

Implementing it was easier said than done. I am having trouble implementing this. Do you think you can add support for feature maps in emftriple?

This is what I have so far, but it's neither correct nor complete:

In Extensions.xtend:

def add(Model graph, EObject eObject, EAttribute feature, Object value, ValueFactory factory) {
        if (feature.getEAttributeType().getName().equals("EFeatureMapEntry")) {
            writeFeatureMap(graph, feature, eObject, factory)
        } else {
            if (value instanceof FeatureEList) {
                // TODO
            } else
                graph.add(eObject.toURI, feature.toURI, value.toLiteral(feature, factory))
        }
    }

def writeFeatureMap(Model graph, EAttribute attribute, EObject owner, ValueFactory factory) {
        val features = featureMaps(owner, attribute);

        features.forEach[
            val value = owner.eGet(it as EStructuralFeature);

            if (it instanceof EAttribute) {
                graph.add(owner, it, value, factory)
            } else {
                val reference = it as EReference;
                if (reference.isContainment()) {
                    reference.eContents.forEach[
                        graph.add(owner, reference, it as EObject) // FIXME
                    ]
                } else {
                    graph.add(owner, reference, value as EObject)
                }
            }
        ]
    }

    static def featureMaps(EObject owner, EAttribute attribute) {
        val featureMap = owner.eGet(attribute) as FeatureMap.Internal;
        val iterator = featureMap.basicIterator();

        val features = new LinkedHashSet();
        while (iterator.hasNext()) {
            features.add(iterator.next().getEStructuralFeature());
        }

        return features;
    }
XDskynet commented 8 years ago

Is there anything done?

I stranded here because of the same reason.

Pleeeeaaase help me :)