diff --git a/examples/omwg/total.xml b/examples/omwg/total.xml index ee73e0591ed492a7aff3bda6033892ba28381440..57c83e7dfaea713f47e1daad1d6f75928b27d73e 100644 --- a/examples/omwg/total.xml +++ b/examples/omwg/total.xml @@ -48,16 +48,16 @@ </Ontology> </onto2> <!-- Class basis --> - <!--map> + <map> <Cell rdf:about="MappingRule_class_basis"> <entity1><edoal:Class rdf:about="&wine;VintageYear"/></entity1> <entity2><edoal:Class rdf:about="&vin;Millesime"/></entity2> <measure rdf:datatype="&xsd;float">1.0</measure> <relation>Equivalence</relation> </Cell> - </map--> + </map> <!-- class const: and or not --> - <!--map> + <map> <Cell rdf:about="MappingRule_class_const"> <entity1> <edoal:Class> @@ -119,9 +119,9 @@ <measure rdf:datatype='&xsd;float'>1.</measure> <relation>SubsumedBy</relation> </Cell> - </map--> + </map> <!-- class rest: att-type... --> - <!--map> + <map> <Cell rdf:about="MappingRule_class_rest"> <entity1> <edoal:Class> @@ -199,43 +199,143 @@ <measure rdf:datatype='&xsd;float'>1.</measure> <relation>SubsumedBy</relation> </Cell> - </map--> + </map> + <!-- a bit more test on values --> + <map> + <Cell rdf:about="MappingRule_class_values"> + <entity1> + <edoal:Class> + <edoal:or rdf:parseType="Collection"> + <edoal:Class rdf:about="&wine;Vin"/> + <edoal:AttributeValueRestriction> + <edoal:onAttribute> + <edoal:Relation> + <edoal:compose rdf:parseType="Collection"> + <edoal:Relation rdf:about="&wine;hasTerroir"/> + <edoal:Relation rdf:about="&proton;locatedIn"/> + </edoal:compose> + </edoal:Relation> + </edoal:onAttribute> + <edoal:comparator rdf:resource="&xsd;equals"/> + <edoal:value><edoal:Instance rdf:about="&wine;Bordelais"/></edoal:value> + </edoal:AttributeValueRestriction> + <edoal:AttributeValueRestriction> + <edoal:onAttribute> + <edoal:Property> + <edoal:compose rdf:parseType="Collection"> + <edoal:Relation rdf:about="&wine;hasTerroir"/> + <edoal:Property rdf:about="&proton;dptnb"/> + </edoal:compose> + </edoal:Property> + </edoal:onAttribute> + <edoal:comparator rdf:resource="&xsd;equals"/> + <edoal:value><edoal:Literal edoal:string="33"/></edoal:value> + </edoal:AttributeValueRestriction> + <edoal:AttributeValueRestriction> + <edoal:onAttribute> + <edoal:Relation> + <edoal:or rdf:parseType="Collection"> + <edoal:Relation rdf:about="&wine;hasTerroir"/> + <edoal:Relation rdf:about="&proton;locatedIn"/> + </edoal:or> + </edoal:Relation> + </edoal:onAttribute> + <edoal:comparator rdf:resource="&xsd;equals"/> + <edoal:value><edoal:Relation rdf:about="&wine;location"/></edoal:value> + </edoal:AttributeValueRestriction> + <edoal:Class rdf:about="&wine;Bordeaux7"/> + </edoal:or> + </edoal:Class> + </entity1> + <entity2> + <edoal:Class> + <edoal:and rdf:parseType="Collection"> + <edoal:Class rdf:about="&vin;Vin"/> + <edoal:AttributeValueRestriction> + <edoal:onAttribute> + <edoal:Property> + <edoal:compose rdf:parseType="Collection"> + <edoal:Relation rdf:about="&vin;hasTerroir"/> + <edoal:Property rdf:about="&proton;dptnb"/> + </edoal:compose> + </edoal:Property> + </edoal:onAttribute> + <edoal:comparator rdf:resource="&xsd;equals"/> + <edoal:value><edoal:Property rdf:about="&vin;matrid"/></edoal:value> + </edoal:AttributeValueRestriction> + <edoal:AttributeValueRestriction> + <edoal:onAttribute> + <edoal:Relation> + <edoal:and rdf:parseType="Collection"> + <edoal:Relation rdf:about="&vin;hasTerroir"/> + <edoal:Relation rdf:about="&proton;locatedIn"/> + </edoal:and> + </edoal:Relation> + </edoal:onAttribute> + <edoal:comparator rdf:resource="&xsd;equals"/> + <edoal:value> + <edoal:Apply edoal:operator="http://example.org/mydummyoperation/"> + <edoal:arguments rdf:parseType="Collection"> + <edoal:Literal edoal:string="43"/> + <edoal:Property rdf:about="&vin;matrid"/> + <edoal:Apply edoal:operator="http://example.org/mydummyoperation2/"> + <edoal:arguments rdf:parseType="Collection"> + <edoal:Literal edoal:string="22"/> + <edoal:Property rdf:about="&vin;matrid"/> + <edoal:Apply edoal:operator="http://example.org/mydummyoperation3/"> + <edoal:arguments rdf:parseType="Collection"/> + </edoal:Apply> + </edoal:arguments> + </edoal:Apply> + <edoal:Relation rdf:about="&vin;hasTerroir"/> + <edoal:Instance rdf:about="&wine;Bordelais"/> + </edoal:arguments> + </edoal:Apply> + </edoal:value> + </edoal:AttributeValueRestriction> + </edoal:and> + </edoal:Class> + </entity2> + <measure rdf:datatype='&xsd;float'>1.</measure> + <relation>SubsumedBy</relation> + </Cell> + </map> <!-- class const and rest --> <!-- rel basis --> - <!--map> + <map> <Cell rdf:about="MappingRule_rel_basis"> <entity1><edoal:Relation rdf:about="&wine;locatedIn"/></entity1> <entity2><edoal:Relation rdf:about="&vin;hasTerroir"/></entity2> <measure rdf:datatype="&xsd;float">1.0</measure> <relation>SubsumedBy</relation> </Cell> - </map--> + </map> <!-- rel const: and or not compose inverse trans refl sym --> <!-- rel rest: att-type... --> <!-- rel const and rest --> <!-- prop basis --> - <!--map> + <map> <Cell rdf:about="MappingRule_prop_basis"> <entity1><edoal:Property rdf:about="&wine;yearValue"/></entity1> <entity2><edoal:Property rdf:about="&vin;anneeMillesime"/></entity2> <measure rdf:datatype="&xsd;float">1.0</measure> <relation>Equivalence</relation> </Cell> - </map--> + </map> <!-- prop const: and or not compose --> <!-- prop rest: att-type... --> <!-- prop const and rest --> <!-- instance --> - <!--map> + <map> <Cell rdf:about="MappingRule_inst_basis"> <entity1><edoal:Instance rdf:about="&wine;ChateauMargaux1995"/></entity1> <entity2><edoal:Instance rdf:about="&vin;MoutonRotschild1889"/></entity2> <measure rdf:datatype="&xsd;float">1.0</measure> <relation>SubsumedBy</relation> </Cell> - </map--> + </map> <!-- Miscelaneous --> - <!--map> + <map> <Cell rdf:about="MappingRule_3"> <entity1> <edoal:Class> @@ -272,8 +372,8 @@ <measure rdf:datatype='&xsd;float'>1.</measure> <relation>SubsumedBy</relation> </Cell> - </map--> - <!--map> + </map> + <map> <Cell rdf:about="MappingRule_4"> <entity1> <edoal:Class> @@ -294,6 +394,6 @@ <measure rdf:datatype='&xsd;float'>1.</measure> <relation>SubsumedBy</relation> </Cell> - </map--> + </map> </Alignment> </rdf:RDF> diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/Apply.java b/src/fr/inrialpes/exmo/align/impl/edoal/Apply.java new file mode 100644 index 0000000000000000000000000000000000000000..be2e2c020d3c642af9e29893b75c8c0d407ff25f --- /dev/null +++ b/src/fr/inrialpes/exmo/align/impl/edoal/Apply.java @@ -0,0 +1,117 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.inrialpes.exmo.align.impl.edoal; + +import java.util.List; +import java.net.URI; +import java.net.URISyntaxException; + +import org.semanticweb.owl.align.Visitable; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.AlignmentVisitor; + +import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; + +/** + * <p> + * Id to represent a simple valuestring. + * </p> + * <p> + * $Id$ + * </p> + * + * @author richi + * @version $Revision: 1.2 $ + * @date $Date: 2010-03-07 20:40:05 +0100 (Sun, 07 Mar 2010) $ + */ +public class Apply implements ValueExpression { + + /** Holds the operation to apply */ + private URI operation; + + private List<ValueExpression> arguments; + + /** + * Constructs an object with the given value. + * + * @param op + * the URI of the operation to apply. + * @param args + * its list of argumenst + * @throws NullPointerException + * if the value is {@code null} + * @throws IllegalArgumentException + * if the value isn't longer than 0 + */ + public Apply( final URI op, final List<ValueExpression> args ) { + if ( op == null) { + throw new NullPointerException("The operation must not be null"); + } + operation = op; + arguments = args; + } + + public void accept(AlignmentVisitor visitor) throws AlignmentException { + visitor.visit(this); + } + + public void accept(TypeCheckingVisitor visitor) throws AlignmentException { + visitor.visit(this); + } + + public URI getOperation() { + return operation; + } + + public List<ValueExpression> getArguments() { + return arguments; + } + + public int hashCode() { + return 5*operation.hashCode() + 13*arguments.hashCode(); + } + + public boolean equals( final Object o ) { + if ( o == this ) return true; + if ( !(o instanceof Apply) ) return false; + Apply a = (Apply)o; + return ( operation.equals(a.getOperation()) && + arguments.equals(a.getArguments()) ); + } + /* + public Object clone() { + return super.clone(); + } + */ + + /** + * <p> + * Returns a short description about this object. <b>The format of the + * returned string is undocumentd and subject to change.</b> + * </p> + * <p> + * An example return string could be: {@code 15} + * </p> + */ + //public String toString() { + // return value; + //} +} diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/ClassValueRestriction.java b/src/fr/inrialpes/exmo/align/impl/edoal/ClassValueRestriction.java index 1c78feb118ac56eb4a01910219649d4a09c9e6a9..bdf7c567c3a921cfab9c7d3b694b75e2fa216aa7 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/ClassValueRestriction.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/ClassValueRestriction.java @@ -39,9 +39,7 @@ package fr.inrialpes.exmo.align.impl.edoal; public class ClassValueRestriction extends ClassRestriction implements Cloneable { Comparator comparator = null; - PathExpression pathValue = null; - Value value = null; - InstanceExpression inst = null; + ValueExpression value = null; /** * Constructs a valueCondition with the given restriction. @@ -53,24 +51,12 @@ public class ClassValueRestriction extends ClassRestriction implements Cloneable * @throws NullPointerException * if the restriction is null */ - public ClassValueRestriction(final PathExpression p, final Comparator comp, final PathExpression p2) { - super(p); - pathValue = p2; - comparator = comp; - } - - public ClassValueRestriction(final PathExpression p, final Comparator comp, final Value v) { + public ClassValueRestriction(final PathExpression p, final Comparator comp, final ValueExpression v) { super(p); value = v; comparator = comp; } - public ClassValueRestriction(final PathExpression p, final Comparator comp, final InstanceExpression i) { - super(p); - inst = i; - comparator = comp; - } - public Comparator getComparator() { return comparator; } @@ -79,33 +65,12 @@ public class ClassValueRestriction extends ClassRestriction implements Cloneable comparator = comp; } - public PathExpression getPathValue() { - return pathValue; - } - - public InstanceExpression getInstanceValue() { - return inst; - } - - public Value getValue() { + public ValueExpression getValue() { return value; } - public void setValue( PathExpression p ) { - pathValue = p; - value = null; - inst = null; - } - - public void setValue( InstanceExpression i ) { - inst = i; - pathValue = null; - value = null; - } - - public void setValue( Value v ) { + public void setValue( ValueExpression v ) { value = v; - pathValue = null; - inst = null; } + } diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/InstanceExpression.java b/src/fr/inrialpes/exmo/align/impl/edoal/InstanceExpression.java index 614398fb0e25ee1e024342532dc1c6974ddef551..0ae5e9872e6b6a49ead34467569f8fd1f0b8e3f0 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/InstanceExpression.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/InstanceExpression.java @@ -40,7 +40,7 @@ import org.semanticweb.owl.align.Visitable; * @version $Revision: 1.4 $ $Date: 2010-03-07 20:40:05 +0100 (Sun, 07 Mar 2010) $ */ -public class InstanceExpression extends Expression { +public class InstanceExpression extends Expression implements ValueExpression { /** * Creates a simple InstaneExpression with the given Id. diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/PathExpression.java b/src/fr/inrialpes/exmo/align/impl/edoal/PathExpression.java index f46e1af742ae2823ee3565205d238aabbbac1ee8..f94f7f660242ce2a9cb1d101022a0ad44f41f84d 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/PathExpression.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/PathExpression.java @@ -43,7 +43,7 @@ import org.semanticweb.owl.align.Visitable; * @version $Revision: 1.5 $ $Date: 2010-03-07 20:40:05 +0100 (Sun, 07 Mar 2010) $ */ -public abstract class PathExpression extends Expression implements Cloneable, Visitable { +public abstract class PathExpression extends Expression implements Cloneable, Visitable, ValueExpression { public PathExpression() { super(); diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/PropertyValueRestriction.java b/src/fr/inrialpes/exmo/align/impl/edoal/PropertyValueRestriction.java index aa34e0e5da74b2019ff3a57000121e5861f0ba0c..0196011047e71cd11b00fb806d49c4a5295984ab 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/PropertyValueRestriction.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/PropertyValueRestriction.java @@ -39,9 +39,7 @@ package fr.inrialpes.exmo.align.impl.edoal; public class PropertyValueRestriction extends PropertyRestriction implements Cloneable { Comparator comparator = null; - PathExpression path = null; - InstanceExpression inst = null; - Value value = null; + ValueExpression value = null; /** * Constructs a attributeValueRestriction with the given restriction. @@ -67,24 +65,12 @@ public class PropertyValueRestriction extends PropertyRestriction implements Clo * @throws NullPointerException * if the restriction is null */ - public PropertyValueRestriction(final Comparator comp, final PathExpression p) { - super(); - comparator = comp; - path = p; - } - - public PropertyValueRestriction(final Comparator comp, final Value v) { + public PropertyValueRestriction(final Comparator comp, final ValueExpression v) { super(); comparator = comp; value = v; } - public PropertyValueRestriction(final Comparator comp, final InstanceExpression i) { - super(); - comparator = comp; - inst = i; - } - public Comparator getComparator(){ return comparator; } @@ -93,31 +79,11 @@ public class PropertyValueRestriction extends PropertyRestriction implements Clo comparator = comp; } - public Value getValue(){ + public ValueExpression getValue(){ return value; } - public void setValue( Value v ){ + public void setValue( ValueExpression v ){ value = v; - path = null; - inst = null; - } - - public InstanceExpression getInstanceValue(){ - return inst; - } - public void setInstanceValue( InstanceExpression i ){ - inst = i; - value = null; - path = null; - } - - public PathExpression getPath(){ - return path; - } - public void setPath( PathExpression p ){ - path = p; - value = null; - inst = null; } /* diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/Value.java b/src/fr/inrialpes/exmo/align/impl/edoal/Value.java index b220d8fbf3cdc23c5513f77c3d671227b6135309..41738ef89d4072036ca802e66981789bc9f831d9 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/Value.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/Value.java @@ -22,6 +22,14 @@ package fr.inrialpes.exmo.align.impl.edoal; +import java.net.URI; + +import org.semanticweb.owl.align.Visitable; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.AlignmentVisitor; + +import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; + /** * <p> * Id to represent a simple valuestring. @@ -34,11 +42,14 @@ package fr.inrialpes.exmo.align.impl.edoal; * @version $Revision: 1.2 $ * @date $Date: 2010-03-07 20:40:05 +0100 (Sun, 07 Mar 2010) $ */ -public class Value { //implements Cloneable, Visitable { +public class Value implements ValueExpression { //implements Cloneable, Visitable { /** Holds the value */ private String value; + /** The eventual type of the value */ + private URI type; + /** * Constructs an object with the given value. * @@ -51,19 +62,38 @@ public class Value { //implements Cloneable, Visitable { */ public Value( final String value ) { if (value == null) { - throw new NullPointerException("The value must not be null"); + throw new NullPointerException("The value should not be null"); } this.value = value; } - // public void accept(AlignmentVisitor visitor) throws AlignmentException { - // visitor.visit(this); - // } + public Value( final String value, final URI type ) { + if (value == null) { + throw new NullPointerException("The value should not be null"); + } + if (type == null) { + throw new NullPointerException("The type is null"); + } + this.value = value; + this.type = type; + } + + public void accept(AlignmentVisitor visitor) throws AlignmentException { + visitor.visit(this); + } - public String plainText() { + public void accept(TypeCheckingVisitor visitor) throws AlignmentException { + visitor.visit(this); + } + + public String getValue() { return value; } + public URI getType() { + return type; + } + public int hashCode() { return 5*value.hashCode(); } diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/ValueExpression.java b/src/fr/inrialpes/exmo/align/impl/edoal/ValueExpression.java new file mode 100644 index 0000000000000000000000000000000000000000..d976ea65d758760a82642771dca7fd573a4e61cc --- /dev/null +++ b/src/fr/inrialpes/exmo/align/impl/edoal/ValueExpression.java @@ -0,0 +1,32 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.inrialpes.exmo.align.impl.edoal; + +import org.semanticweb.owl.align.Visitable; + +/** + * Interface implemented by expressions which can be used as values: + * Value, Path, Instance + */ + +public interface ValueExpression extends Visitable { +} + diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java index c2db45dbad0f10b789b71ecb77e842c488754c86..a94d2ff985e3f4d2a6aeb9157286c35eb8fcf7cd 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java @@ -75,7 +75,9 @@ import fr.inrialpes.exmo.align.impl.edoal.InstanceExpression; import fr.inrialpes.exmo.align.impl.edoal.InstanceId; import fr.inrialpes.exmo.align.impl.edoal.TransfService; +import fr.inrialpes.exmo.align.impl.edoal.ValueExpression; import fr.inrialpes.exmo.align.impl.edoal.Value; +import fr.inrialpes.exmo.align.impl.edoal.Apply; import fr.inrialpes.exmo.align.impl.edoal.Datatype; import fr.inrialpes.exmo.align.impl.edoal.Comparator; @@ -418,23 +420,7 @@ public class RDFRendererVisitor implements AlignmentVisitor { writer.print("=\""+((ClassValueRestriction)c).getComparator().getURI()); writer.print("\"/>"+NL); indentedOutput("<"+SyntaxElement.VALUE.print(DEF)+">"); - if ( c.getValue() != null ) { - visit( c.getValue() ); - } else if ( c.getInstanceValue() != null ) { - increaseIndent(); - writer.print(NL); - visit( c.getInstanceValue() ); - writer.print(NL); - decreaseIndent(); - indentedOutputln(); - } else { - increaseIndent(); - writer.print(NL); - visit( c.getPathValue() ); - writer.print(NL); - decreaseIndent(); - indentedOutputln(); - } + visit( c.getValue() ); writer.print("</"+SyntaxElement.VALUE.print(DEF)+">"+NL); decreaseIndent(); indentedOutput("</"+SyntaxElement.PROPERTY_VALUE_COND.print(DEF)+">"); @@ -575,13 +561,7 @@ public class RDFRendererVisitor implements AlignmentVisitor { writer.print("=\""+c.getComparator().getURI()); writer.print("\"/>"); writer.print("<"+SyntaxElement.VALUE.print(DEF)+">"); - if ( c.getValue() != null ) { - visit( c.getValue() ); - } else if ( c.getInstanceValue() != null ) { - visit( c.getInstanceValue() ); - } else { - visit( c.getPath() ); - } + visit( c.getValue() ); writer.print("</"+SyntaxElement.VALUE.print(DEF)+">"+NL); decreaseIndent(); indentedOutput("</"+SyntaxElement.VALUE_COND.print(DEF)+">"); @@ -719,10 +699,39 @@ public class RDFRendererVisitor implements AlignmentVisitor { } // DONE+TESTED + public void visit( final ValueExpression e ) throws AlignmentException { + if ( e instanceof InstanceExpression ) visit( (InstanceExpression)e ); + else if ( e instanceof PathExpression ) visit( (PathExpression)e ); + else if ( e instanceof Apply ) visit( (Apply)e ); + else if ( e instanceof Value ) visit( (Value)e ); + else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); + } + public void visit( final Value e ) throws AlignmentException { - writer.print(e.plainText()); + indentedOutput("<"+SyntaxElement.LITERAL.print(DEF)+" "+SyntaxElement.STRING.print(DEF)+"=\""); + writer.print(e.getValue()); + if ( e.getType() != null ) { + writer.print(" "+SyntaxElement.TYPE.print(DEF)+"=\""+e.getType()+"\""); + } + writer.print("\"/>"); } + public void visit( final Apply e ) throws AlignmentException { + indentedOutput("<"+SyntaxElement.APPLY.print(DEF)+" "+SyntaxElement.OPERATOR.print(DEF)+"=\""+e.getOperation()+"\">"+NL); + increaseIndent(); + indentedOutput("<"+SyntaxElement.ARGUMENTS.print(DEF)+" "+SyntaxElement.RDF_PARSETYPE.print(DEF)+"=\"Collection\">"+NL); + increaseIndent(); + for ( final ValueExpression ve : e.getArguments() ) { + writer.print(linePrefix); + visit( ve ); + writer.print(NL); + } + decreaseIndent(); + indentedOutput("</"+SyntaxElement.ARGUMENTS.print(DEF)+">"+NL); + decreaseIndent(); + writer.print("</"+SyntaxElement.APPLY.print(DEF)+">"); + } + // DONE public void visit( final Datatype e ) throws AlignmentException { indentedOutput("<"+SyntaxElement.DATATYPE.print(DEF)+">"); diff --git a/src/fr/inrialpes/exmo/align/parser/RDFParser.java b/src/fr/inrialpes/exmo/align/parser/RDFParser.java index 5a946617c5ccd522af75823723d64c72c1315755..dc8cbde25d05adfd2b206ede34b9db7556da3392 100644 --- a/src/fr/inrialpes/exmo/align/parser/RDFParser.java +++ b/src/fr/inrialpes/exmo/align/parser/RDFParser.java @@ -62,7 +62,9 @@ import fr.inrialpes.exmo.align.impl.edoal.InstanceExpression; import fr.inrialpes.exmo.align.impl.edoal.InstanceId; import fr.inrialpes.exmo.align.impl.edoal.TransfService; +import fr.inrialpes.exmo.align.impl.edoal.ValueExpression; import fr.inrialpes.exmo.align.impl.edoal.Value; +import fr.inrialpes.exmo.align.impl.edoal.Apply; import fr.inrialpes.exmo.align.impl.edoal.Datatype; import fr.inrialpes.exmo.align.impl.edoal.Comparator; import fr.inrialpes.exmo.align.impl.edoal.Variable; @@ -514,19 +516,11 @@ public class RDFParser { } } else { // Find comparator - // JE2010: This is not good as comparator management... stmt = node.getProperty( (Property)SyntaxElement.COMPARATOR.resource ); if ( stmt == null ) throw new AlignmentException( "Required edoal:comparator property" ); URI id = getNodeId( stmt.getResource() ); if ( id != null ) comp = new Comparator( id ); - else throw new AlignmentException("Cannot parse anonymous individual"); - /* - try { - comp = new Comparator ( new URI( stmt.getResource().getURI() ) ); - } catch ( URISyntaxException usex ) { - throw new AlignmentException( "Bad URI for comparator: "+stmt.getResource().getURI(), usex ); - } - */ + else throw new AlignmentException("edoal:comparator requires an URI"); if ( rdfType.equals( SyntaxElement.PROPERTY_OCCURENCE_COND.resource ) ) { stmt = node.getProperty( (Property)SyntaxElement.VALUE.resource ); if ( stmt == null ) throw new AlignmentException( "Required edoal:value property" ); @@ -539,6 +533,9 @@ public class RDFParser { } else if ( rdfType.equals( SyntaxElement.PROPERTY_VALUE_COND.resource ) ) { stmt = node.getProperty( (Property)SyntaxElement.VALUE.resource ); if ( stmt == null ) throw new AlignmentException( "Required edoal:value property" ); + ValueExpression v = parseValue( stmt.getObject() ); + return new ClassValueRestriction( pe, comp, v ); + /* TO SUPPRESS RDFNode nn = stmt.getObject(); if ( nn.isLiteral() ) { return new ClassValueRestriction( pe, comp, new Value( ((Literal)nn).getString() ) ); @@ -554,7 +551,7 @@ public class RDFParser { } // This one will raise the error } else { throw new AlignmentException( "Bad edoal:value value" ); - } + }*/ } } } @@ -660,17 +657,13 @@ public class RDFParser { stmt = node.getProperty( (Property)SyntaxElement.COMPARATOR.resource ); if ( stmt == null ) throw new AlignmentException( "Required edoal:comparator property" ); URI id = getNodeId( stmt.getResource() ); - if ( id == null ) throw new AlignmentException("Bad comparator"); + if ( id == null ) throw new AlignmentException("edoal:comparator requires and URI"); Comparator comp = new Comparator( id ); - /* - try { - comp = new Comparator ( new URI( stmt.getResource().getURI() ) ); - } catch ( URISyntaxException usex ) { - throw new AlignmentException( "Bad URI for comparator: "+stmt.getResource().getURI(), usex ); - } - */ stmt = node.getProperty( (Property)SyntaxElement.VALUE.resource ); if ( stmt == null ) throw new AlignmentException( "Required edoal:value property" ); + ValueExpression v = parseValue( stmt.getObject() ); + return new PropertyValueRestriction( comp, v ); + /* RDFNode nn = stmt.getObject(); if ( nn.isLiteral() ) { return new PropertyValueRestriction( comp, new Value( ((Literal)nn).getString() ) ); @@ -685,7 +678,7 @@ public class RDFParser { } } else { throw new AlignmentException( "Bad edoal:value value" ); - } + }*/ } else { throw new AlignmentException("There is no pasrser for entity "+rdfType.getLocalName()); } @@ -786,8 +779,57 @@ public class RDFParser { } } - protected Value parseValue( final Resource node ) throws AlignmentException { - return null; + protected ValueExpression parseValue( final RDFNode node ) throws AlignmentException { + if ( node.isLiteral() ) { // should not appear anymore + return new Value( ((Literal)node).getString() ); + } else if ( node.isResource() ) { + Resource nodeType = ((Resource)node).getProperty(RDF.type).getResource(); + if ( nodeType.equals( SyntaxElement.INSTANCE_EXPR.resource ) ) { + return parseInstance( (Resource)node ); + } else if ( nodeType.equals( SyntaxElement.LITERAL.resource ) ) { + if ( ((Resource)node).hasProperty( (Property)SyntaxElement.STRING.resource ) ) { + if ( ((Resource)node).hasProperty( (Property)SyntaxElement.TYPE.resource ) ) { + try { + return new Value( ((Resource)node).getProperty( (Property)SyntaxElement.STRING.resource ).getLiteral().getString(), new URI( ((Resource)node).getProperty( (Property)SyntaxElement.TYPE.resource ).getLiteral().getString() ) ); + } catch (URISyntaxException urisex) { + throw new AlignmentException( "Incorect URI for edoal:type : "+ ((Resource)node).getProperty( (Property)SyntaxElement.TYPE.resource ).getLiteral().getString() ); + } + } else { + return new Value( ((Resource)node).getProperty( (Property)SyntaxElement.STRING.resource ).getLiteral().getString() ); + } + } else { + throw new AlignmentException( "edoal:Literal requires a edoal:value" ); + } + } else if ( nodeType.equals( SyntaxElement.APPLY.resource ) ) { + // Get the operation + URI op; + if ( ((Resource)node).hasProperty( (Property)SyntaxElement.OPERATOR.resource ) ) { + String operation = ((Resource)node).getProperty( (Property)SyntaxElement.OPERATOR.resource ).getLiteral().getString(); + try { + op = new URI( operation ); + } catch (URISyntaxException e) { + throw new AlignmentException( "edoal:Apply incorrect operation URI : "+operation ); + } + } else { + throw new AlignmentException( "edoal:Apply requires an operation" ); + } + // Get all arguments + List<ValueExpression> valexpr = new LinkedList<ValueExpression>(); + if ( ((Resource)node).hasProperty( (Property)SyntaxElement.ARGUMENTS.resource ) ) { + Statement stmt = ((Resource)node).getProperty( (Property)SyntaxElement.ARGUMENTS.resource ); + Resource coll = stmt.getResource(); //JE2010MUSTCHECK + while ( !RDF.nil.getURI().equals( coll.getURI() ) ) { + valexpr.add( parseValue( coll.getProperty( RDF.first ).getResource() ) ); + coll = coll.getProperty( RDF.rest ).getResource(); + } + } + return new Apply( op, valexpr ); + } else { // JE2010: Check that pe is a Path + return parsePathExpression( (Resource)node ); + } + } else { + throw new AlignmentException( "Bad edoal:value value" ); + } } protected URI getNodeId( final Resource node ) throws AlignmentException { diff --git a/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java b/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java index 976ee2cecce6d881ec5d672c576522dae45ff73e..beaa68c4d81ee66c02e51874e805da9fa61c7738 100644 --- a/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java +++ b/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java @@ -4,7 +4,7 @@ * Copyright (C) 2006 Digital Enterprise Research Insitute (DERI) Innsbruck * Copyright (C) 2005 Digital Enterprise Research Insitute (DERI) Galway * Sourceforge version 1.6 - 2008 - then OmwgElement - * Copyright (C) INRIA, 2008-2009 + * Copyright (C) INRIA, 2008-2010 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -90,7 +90,7 @@ public enum SyntaxElement { // EDOAL NAMESPACE AND( Namespace.EDOAL, "and", Constructor.AND), APPLY( Namespace.EDOAL, "Apply", true), - //ARGUMENTS( Namespace.EDOAL, "arguments"), + ARGUMENTS( Namespace.EDOAL, "arguments"), ATTR_TRANSF( Namespace.EDOAL, "transf"), CLASS_EXPR( Namespace.EDOAL, "Class", true),//ALIGNMENT CODOMAIN_RESTRICTION(Namespace.EDOAL, "CodomainRestriction", true), @@ -98,17 +98,15 @@ public enum SyntaxElement { COMPOSE( Namespace.EDOAL, "compose", Constructor.COMP), DATATYPE( Namespace.EDOAL, "datatype"), DOMAIN_RESTRICTION(Namespace.EDOAL, "DomainRestriction", true), - //FIRST( Namespace.EDOAL, "first"), //ID( Namespace.EDOAL, "Id", true), // Useless INSTANCE_EXPR( Namespace.EDOAL, "Instance", true), INVERSE( Namespace.EDOAL, "inverse", Constructor.INVERSE), - //NEXT( Namespace.EDOAL, "next"), + LITERAL( Namespace.EDOAL, "Literal", true), NOT( Namespace.EDOAL, "not", Constructor.NOT), ONPROPERTY( Namespace.EDOAL, "onAttribute"), + OPERATOR( Namespace.EDOAL, "operator"), OR( Namespace.EDOAL, "or", Constructor.OR), //PARAMETERS( Namespace.EDOAL, "parameters"), - //PATH( Namespace.EDOAL, "Path", true), - //PROPERTIES( Namespace.EDOAL, "properties"), PROPERTY( Namespace.EDOAL, "Property", true), PROPERTY_EXPR( Namespace.EDOAL, "Property"), // ?? PROPERTY_OCCURENCE_COND(Namespace.EDOAL, "AttributeOccurenceRestriction", true), @@ -117,8 +115,8 @@ public enum SyntaxElement { PROPERTY_VALUE_COND(Namespace.EDOAL, "AttributeValueRestriction", true), REFLEXIVE( Namespace.EDOAL, "reflexive", Constructor.REFLEXIVE), RELATION_EXPR( Namespace.EDOAL, "Relation", true), - //RESTRICTION(Namespace.EDOAL, "Restriction"), //SERVICE( Namespace.EDOAL, "service"), + STRING( Namespace.EDOAL, "string"), SYMMETRIC( Namespace.EDOAL, "symmetric", Constructor.SYMMETRIC), TOCLASS( Namespace.EDOAL, "class"), TRANSF( Namespace.EDOAL, "transf"), diff --git a/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java b/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java index af1ebaa7939fd2b653bd3375dfe5665c673af783..4eab3a81cd16719b95562f6f98e01397f5a3f47f 100644 --- a/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java +++ b/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java @@ -73,6 +73,8 @@ import fr.inrialpes.exmo.align.impl.edoal.InstanceId; import fr.inrialpes.exmo.align.impl.edoal.TransfService; import fr.inrialpes.exmo.align.impl.edoal.Value; +import fr.inrialpes.exmo.align.impl.edoal.ValueExpression; +import fr.inrialpes.exmo.align.impl.edoal.Apply; import fr.inrialpes.exmo.align.impl.edoal.Datatype; import fr.inrialpes.exmo.align.impl.edoal.Comparator; @@ -169,13 +171,7 @@ public class TypeCheckingVisitor { public void visit( final ClassValueRestriction c ) throws AlignmentException { visit( c.getRestrictionPath() ); - if ( c.getValue() != null ) { - visit( c.getValue() ); - } else if ( c.getInstanceValue() != null ) { - visit( c.getInstanceValue() ); - } else { - visit( c.getPathValue() ); - } + visit( c.getValue() ); } public void visit( final ClassTypeRestriction c ) throws AlignmentException { @@ -220,13 +216,7 @@ public class TypeCheckingVisitor { public void visit(final PropertyValueRestriction c) throws AlignmentException { c.getComparator().getURI(); - if ( c.getValue() != null ) { - visit( c.getValue() ); - } else if ( c.getInstanceValue() != null ) { - visit( c.getInstanceValue() ); - } else { - visit( c.getPath() ); - } + visit( c.getValue() ); } public void visit(final PropertyDomainRestriction c) throws AlignmentException { @@ -279,6 +269,12 @@ public class TypeCheckingVisitor { public void visit( final Value e ) throws AlignmentException { } + public void visit( final ValueExpression e ) throws AlignmentException { + } + + public void visit( final Apply e ) throws AlignmentException { + } + public void visit( final Datatype e ) throws AlignmentException { }