Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 6a1bf830 authored by Thinh Dong's avatar Thinh Dong
Browse files

- Updated Graph patterns renderer

parent 99c4f9ce
Branches
Tags
No related merge requests found
...@@ -43,36 +43,28 @@ import fr.inrialpes.exmo.align.impl.edoal.ClassDomainRestriction; ...@@ -43,36 +43,28 @@ import fr.inrialpes.exmo.align.impl.edoal.ClassDomainRestriction;
import fr.inrialpes.exmo.align.impl.edoal.ClassExpression; import fr.inrialpes.exmo.align.impl.edoal.ClassExpression;
import fr.inrialpes.exmo.align.impl.edoal.ClassId; import fr.inrialpes.exmo.align.impl.edoal.ClassId;
import fr.inrialpes.exmo.align.impl.edoal.ClassOccurenceRestriction; import fr.inrialpes.exmo.align.impl.edoal.ClassOccurenceRestriction;
import fr.inrialpes.exmo.align.impl.edoal.ClassRestriction;
import fr.inrialpes.exmo.align.impl.edoal.ClassTypeRestriction; import fr.inrialpes.exmo.align.impl.edoal.ClassTypeRestriction;
import fr.inrialpes.exmo.align.impl.edoal.ClassValueRestriction; import fr.inrialpes.exmo.align.impl.edoal.ClassValueRestriction;
import fr.inrialpes.exmo.align.impl.edoal.Comparator; import fr.inrialpes.exmo.align.impl.edoal.Comparator;
import fr.inrialpes.exmo.align.impl.edoal.Datatype; import fr.inrialpes.exmo.align.impl.edoal.Datatype;
import fr.inrialpes.exmo.align.impl.edoal.EDOALVisitor; import fr.inrialpes.exmo.align.impl.edoal.EDOALVisitor;
import fr.inrialpes.exmo.align.impl.edoal.Expression;
import fr.inrialpes.exmo.align.impl.edoal.InstanceExpression;
import fr.inrialpes.exmo.align.impl.edoal.InstanceId; import fr.inrialpes.exmo.align.impl.edoal.InstanceId;
import fr.inrialpes.exmo.align.impl.edoal.PathExpression; import fr.inrialpes.exmo.align.impl.edoal.PathExpression;
import fr.inrialpes.exmo.align.impl.edoal.PropertyConstruction; import fr.inrialpes.exmo.align.impl.edoal.PropertyConstruction;
import fr.inrialpes.exmo.align.impl.edoal.PropertyDomainRestriction; import fr.inrialpes.exmo.align.impl.edoal.PropertyDomainRestriction;
import fr.inrialpes.exmo.align.impl.edoal.PropertyExpression;
import fr.inrialpes.exmo.align.impl.edoal.PropertyId; import fr.inrialpes.exmo.align.impl.edoal.PropertyId;
import fr.inrialpes.exmo.align.impl.edoal.PropertyRestriction;
import fr.inrialpes.exmo.align.impl.edoal.PropertyTypeRestriction; import fr.inrialpes.exmo.align.impl.edoal.PropertyTypeRestriction;
import fr.inrialpes.exmo.align.impl.edoal.PropertyValueRestriction; import fr.inrialpes.exmo.align.impl.edoal.PropertyValueRestriction;
import fr.inrialpes.exmo.align.impl.edoal.RelationCoDomainRestriction; import fr.inrialpes.exmo.align.impl.edoal.RelationCoDomainRestriction;
import fr.inrialpes.exmo.align.impl.edoal.RelationConstruction; import fr.inrialpes.exmo.align.impl.edoal.RelationConstruction;
import fr.inrialpes.exmo.align.impl.edoal.RelationDomainRestriction; import fr.inrialpes.exmo.align.impl.edoal.RelationDomainRestriction;
import fr.inrialpes.exmo.align.impl.edoal.RelationExpression;
import fr.inrialpes.exmo.align.impl.edoal.RelationId; import fr.inrialpes.exmo.align.impl.edoal.RelationId;
import fr.inrialpes.exmo.align.impl.edoal.RelationRestriction;
import fr.inrialpes.exmo.align.impl.edoal.Transformation; import fr.inrialpes.exmo.align.impl.edoal.Transformation;
import fr.inrialpes.exmo.align.impl.edoal.Value; import fr.inrialpes.exmo.align.impl.edoal.Value;
import fr.inrialpes.exmo.align.impl.edoal.ValueExpression;
import fr.inrialpes.exmo.align.parser.SyntaxElement.Constructor; import fr.inrialpes.exmo.align.parser.SyntaxElement.Constructor;
/** /**
* Translate BGP from alignment * Translate correspondences into Graph Patterns
* *
* @author * @author
* @version * @version
...@@ -88,13 +80,12 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -88,13 +80,12 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
protected boolean ignoreerrors = false; protected boolean ignoreerrors = false;
protected static boolean blanks = false; protected static boolean blanks = false;
protected boolean weakens = false; protected boolean weakens = false;
private boolean classValueCond = false;
private String instance = null; private String instance = null;
private String value = ""; private String value = "";
private String uriType = null; private String uriType = null;
private String datatype = ""; private String datatype = "";
private Object valueRestriction = null; private Object valueRestriction = null;
private boolean isValueRestriction = false;
private Stack<String> stackBGP = new Stack<String>(); private Stack<String> stackBGP = new Stack<String>();
private Stack<Constructor> stackOp = new Stack<Constructor>(); private Stack<Constructor> stackOp = new Stack<Constructor>();
...@@ -128,7 +119,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -128,7 +119,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
super( writer ); super( writer );
} }
public static void resetVariablesName(String s, String o) { public static void resetVariablesName( String s, String o ) {
count = 1; count = 1;
sub = "?" + s; sub = "?" + s;
if ( blanks ) { if ( blanks ) {
...@@ -139,7 +130,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -139,7 +130,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
} }
} }
public void resetVariables(String s, String o) { public void resetVariables( String s, String o ) {
resetVariablesName(s, o); resetVariablesName(s, o);
strBGP = ""; strBGP = "";
strBGP_Or = ""; strBGP_Or = "";
...@@ -151,11 +142,11 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -151,11 +142,11 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
} }
public List<String> getBGP(){ public List<String> getBGP(){
try { try {
listBGP.add(strBGP); listBGP.add( strBGP );
} }
catch (Exception e) { catch (Exception e) {
System.err.println("No query!"); System.err.println( "No query!" );
} }
return listBGP; return listBGP;
} }
...@@ -164,24 +155,24 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -164,24 +155,24 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
return listCond; return listCond;
} }
public String getPrefixDomain(URI u) { public String getPrefixDomain( URI u ) {
String str = u.toString(); String str = u.toString();
int index; int index;
if (str.contains("#")) if ( str.contains("#") )
index = str.lastIndexOf("#"); index = str.lastIndexOf("#");
else else
index = str.lastIndexOf("/"); index = str.lastIndexOf("/");
return str.substring(0, index+1); return str.substring(0, index+1);
} }
public String getPrefixName(URI u) { public String getPrefixName( URI u ) {
String str = u.toString(); String str = u.toString();
int index; int index;
if (str.contains("#")) if ( str.contains("#") )
index = str.lastIndexOf("#"); index = str.lastIndexOf("#");
else else
index = str.lastIndexOf("/"); index = str.lastIndexOf("/");
return str.substring(index+1); return str.substring( index+1 );
} }
public static String getNamespace(){ public static String getNamespace(){
...@@ -194,48 +185,25 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -194,48 +185,25 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
FileWriter writer = new FileWriter( dir+"query"+number +".rq" ); FileWriter writer = new FileWriter( dir+"query"+number +".rq" );
out = new BufferedWriter( writer ); out = new BufferedWriter( writer );
number++; number++;
out.write(query); out.write( query );
if ( out != null ) // there was at least one file if ( out != null ) // there was at least one file
out.close(); out.close();
} catch(IOException ioe) { } catch(IOException ioe) {
System.err.println(ioe); System.err.println( ioe );
} }
} }
public void visit( Expression o ) throws AlignmentException {
if ( o instanceof PathExpression ) visit( (PathExpression)o );
else if ( o instanceof ClassExpression ) visit( (ClassExpression)o );
else if ( o instanceof InstanceExpression ) visit( (InstanceExpression)o );
else throw new AlignmentException( "Cannot dispatch Expression "+o );
}
// DONE
public void visit( final PathExpression p ) throws AlignmentException {
if ( p instanceof RelationExpression ) visit( (RelationExpression)p );
else if ( p instanceof PropertyExpression ) visit( (PropertyExpression)p );
else throw new AlignmentException( "Cannot dispatch PathExpression "+p );
}
// DONE
public void visit( final ClassExpression e ) throws AlignmentException {
if ( e instanceof ClassId ) visit( (ClassId)e );
else if ( e instanceof ClassConstruction ) visit( (ClassConstruction)e );
else if ( e instanceof ClassRestriction ) visit( (ClassRestriction)e );
else throw new AlignmentException( "Cannot dispatch ClassExpression "+e );
}
// DONE+TESTED
public void visit( final ClassId e ) throws AlignmentException { public void visit( final ClassId e ) throws AlignmentException {
if ( e.getURI() != null ) { if ( e.getURI() != null ) {
String prefix = getPrefixDomain(e.getURI()); String prefix = getPrefixDomain(e.getURI());
String tag = getPrefixName(e.getURI()); String tag = getPrefixName(e.getURI());
String shortCut; String shortCut;
if(!prefixList.containsKey(prefix)){ if( !prefixList.containsKey(prefix) ){
shortCut = getNamespace(); shortCut = getNamespace();
prefixList.put(prefix, shortCut); prefixList.put( prefix, shortCut );
} }
else { else {
shortCut = prefixList.get(prefix); shortCut = prefixList.get( prefix );
} }
//if (flagRestriction == 1){ //if (flagRestriction == 1){
//strBGP += "?p rdfs:domain " + shortCut + ":"+ tag + " ." + NL; //strBGP += "?p rdfs:domain " + shortCut + ":"+ tag + " ." + NL;
...@@ -255,21 +223,21 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -255,21 +223,21 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
} }
else { else {
strBGP += sub + " a " + shortCut + ":"+ tag + " ." + NL; strBGP += sub + " a " + shortCut + ":"+ tag + " ." + NL;
if (op != Constructor.NOT) { if ( op != Constructor.NOT ) {
Stack<String> tempStack = new Stack<String>(); Stack<String> tempStack = new Stack<String>();
if (stackBGP.isEmpty()){ if ( stackBGP.empty() ){
strBGP_Or = sub + " a " + shortCut + ":"+ tag + " ." + NL; strBGP_Or = sub + " a " + shortCut + ":"+ tag + " ." + NL;
tempStack.push(strBGP_Or); tempStack.push( strBGP_Or );
} }
else { else {
while (!stackBGP.isEmpty()){ while ( !stackBGP.empty() ){
strBGP_Or = stackBGP.pop(); strBGP_Or = stackBGP.pop();
strBGP_Or += sub + " a " + shortCut + ":"+ tag + " ." + NL; strBGP_Or += sub + " a " + shortCut + ":"+ tag + " ." + NL;
tempStack.push(strBGP_Or); tempStack.push( strBGP_Or );
} }
} }
while (!tempStack.isEmpty()){ while ( !tempStack.empty() ){
stackBGP.push(tempStack.pop()); stackBGP.push( tempStack.pop() );
} }
} }
...@@ -277,59 +245,58 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -277,59 +245,58 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
} }
} }
// DONE+TESTED
public void visit( final ClassConstruction e ) throws AlignmentException { public void visit( final ClassConstruction e ) throws AlignmentException {
op = e.getOperator(); op = e.getOperator();
countInList = 0; countInList = 0;
if (op == Constructor.OR){ if (op == Constructor.OR) {
int size = e.getComponents().size(); int size = e.getComponents().size();
Stack<String> tempStack = new Stack<String>(); Stack<String> tempStack = new Stack<String>();
Stack<String> tempResult = new Stack<String>(); Stack<String> tempResult = new Stack<String>();
while(!stackBGP.empty()){
while( !stackBGP.empty() ) {
tempStack.push(stackBGP.pop()); tempStack.push(stackBGP.pop());
} }
for ( final ClassExpression ce : e.getComponents() ) { for ( final ClassExpression ce : e.getComponents() ) {
strBGP += "{" + NL; strBGP += "{" + NL;
if(op != null){ if( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
stackBGP.clear(); stackBGP.clear();
if(!tempStack.empty()){ if( !tempStack.empty() ) {
for(int i=0; i<tempStack.size(); i++) for( int i=0; i<tempStack.size(); i++ ) {
stackBGP.push(tempStack.get(i)); stackBGP.push( tempStack.get(i) );
}
} }
countInList++; countInList++;
visit( ce ); ce.accept( this );
if(!stackOp.empty()) {
if(op == Constructor.NOT)
stackBGP.clear();
if(!stackOp.isEmpty())
op = stackOp.pop(); op = stackOp.pop();
}
while(!stackBGP.empty()){ if( op == Constructor.NOT ) {
tempResult.push(stackBGP.pop()); stackBGP.clear();
} }
while( !stackBGP.empty() ) {
tempResult.push( stackBGP.pop() );
}
size--; size--;
if(size != 0) if( size != 0 )
strBGP += "}" + " UNION " + NL; strBGP += "}" + " UNION " + NL;
else else
strBGP += "}" + NL; strBGP += "}" + NL;
} }
while(!tempResult.empty()){ while( !tempResult.empty() ) {
stackBGP.push(tempResult.pop()); stackBGP.push( tempResult.pop() );
} }
} }
else if (op == Constructor.NOT){ else if ( op == Constructor.NOT ) {
for ( final ClassExpression ce : e.getComponents() ) { for ( final ClassExpression ce : e.getComponents() ) {
strBGP +="MINUS {" + NL + INDENT; strBGP +="MINUS {" + NL + INDENT;
if(op != null){ if( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
visit( ce ); ce.accept( this );
if(!stackOp.isEmpty()) if( !stackOp.empty() )
op = stackOp.pop(); op = stackOp.pop();
strBGP +="}" + NL; strBGP +="}" + NL;
} }
...@@ -337,65 +304,75 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -337,65 +304,75 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
} }
else { else {
for ( final ClassExpression ce : e.getComponents() ) { for ( final ClassExpression ce : e.getComponents() ) {
if(op != null){ if( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
visit( ce ); ce.accept( this );
if(!stackOp.isEmpty()) stackBGP.clear();
if( !stackOp.empty() )
op = stackOp.pop(); op = stackOp.pop();
} }
} }
if(stackOp.isEmpty()) { if( stackOp.empty() ) {
if(op == Constructor.NOT || flagRestriction == 1) if( op == Constructor.NOT || flagRestriction == 1 )
stackBGP.clear(); stackBGP.clear();
while (!stackBGP.empty()){ while ( !stackBGP.empty() ) {
listBGP.add(stackBGP.pop()); listBGP.add( stackBGP.pop() );
} }
} }
op = null; //op = null;
}
// DONE+TESTED
public void visit(final ClassRestriction e) throws AlignmentException {
if ( e instanceof ClassValueRestriction ) visit( (ClassValueRestriction)e );
else if ( e instanceof ClassTypeRestriction ) visit( (ClassTypeRestriction)e );
else if ( e instanceof ClassDomainRestriction ) visit( (ClassDomainRestriction)e );
else if ( e instanceof ClassOccurenceRestriction ) visit( (ClassOccurenceRestriction)e );
else throw new AlignmentException( "Cannot dispatch ClassExpression "+e );
objectsRestriction.clear();
} }
// DONE+TESTED
public void visit( final ClassValueRestriction c ) throws AlignmentException { public void visit( final ClassValueRestriction c ) throws AlignmentException {
instance = null; String str = "";
instance = "";
value = ""; value = "";
isValueRestriction = true;
flagRestriction = 1; flagRestriction = 1;
visit( c.getValue() ); c.getValue().accept( this );
flagRestriction = 0; flagRestriction = 0;
if(instance != null) if( !instance.equals("") )
valueRestriction = instance; valueRestriction = instance;
else if(!value.equals("")) else if( !value.equals("") )
valueRestriction = value; valueRestriction = value;
visit( c.getRestrictionPath() ); if( c.getComparator().getURI().equals( Comparator.GREATER.getURI() ) ) {
opOccurence = ">";
classValueCond = true;
}
if( c.getComparator().getURI().equals( Comparator.LOWER.getURI() ) ) {
opOccurence = "<";
classValueCond = true;
}
c.getRestrictionPath().accept( this );
isValueRestriction = false;
String temp = obj; String temp = obj;
Iterator<String> listObj = objectsRestriction.iterator(); if ( ( c.getComparator().getURI().equals( Comparator.GREATER.getURI() )
while ( listObj.hasNext() ) { || c.getComparator().getURI().equals( Comparator.LOWER.getURI() ) )
obj = listObj.next(); && !objectsRestriction.isEmpty() ) {
flagRestriction = 1; Iterator<String> listObj = objectsRestriction.iterator();
visit( c.getValue() ); if (op == Constructor.COMP) {
flagRestriction = 0; str = "FILTER(" + listObj.next() + opOccurence + valueRestriction + ")" +NL;
} }
else{
while ( listObj.hasNext() ) {
str += "FILTER(" + listObj.next() + opOccurence + valueRestriction + ")" +NL;
}
}
while( countInList > listCond.size() )
listCond.add( "" );
if( countInList>0 )
listCond.add( countInList-1, str );
else
listCond.add( countInList, str );
strBGP += str;
}
valueRestriction = null; valueRestriction = null;
obj = temp; obj = temp;
if(op == Constructor.AND){ if( op == Constructor.AND ){
if ( blanks ) { if ( blanks ) {
obj = "_:o" + ++count; obj = "_:o" + ++count;
} }
...@@ -403,18 +380,18 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -403,18 +380,18 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
obj = "?o" + ++count; obj = "?o" + ++count;
} }
} }
if( stackBGP.size() > 0 )
stackBGP.remove( stackBGP.size()-1 );
} }
// DONE+TESTED
public void visit( final ClassTypeRestriction c ) throws AlignmentException { public void visit( final ClassTypeRestriction c ) throws AlignmentException {
String str = ""; String str = "";
datatype = ""; datatype = "";
visit( c.getRestrictionPath() ); c.getRestrictionPath().accept( this );
if ( !objectsRestriction.isEmpty() ) { if ( !objectsRestriction.isEmpty() ) {
Iterator<String> listObj = objectsRestriction.iterator(); Iterator<String> listObj = objectsRestriction.iterator();
int size = objectsRestriction.size(); int size = objectsRestriction.size();
if (size > 0) { if ( size > 0 ) {
increaseIndent(); increaseIndent();
str = "FILTER (datatype(" + listObj.next() + ") = "; str = "FILTER (datatype(" + listObj.next() + ") = ";
visit( c.getType() ); visit( c.getType() );
...@@ -426,182 +403,184 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -426,182 +403,184 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
str += "xsd:" + datatype; str += "xsd:" + datatype;
} }
str += ")" + NL; str += ")" + NL;
while(countInList > listCond.size()) while( countInList > listCond.size() )
listCond.add(""); listCond.add( "" );
if(countInList>0) if(countInList>0)
listCond.add(countInList-1, str); listCond.add( countInList-1, str );
else else
listCond.add(countInList, str); listCond.add( countInList, str );
strBGP += str; strBGP += str;
} }
objectsRestriction.clear(); objectsRestriction.clear();
} }
// DONE+TESTED
public void visit( final ClassDomainRestriction c ) throws AlignmentException { public void visit( final ClassDomainRestriction c ) throws AlignmentException {
visit( c.getRestrictionPath() ); c.getRestrictionPath().accept( this );
Iterator<String> listObj = objectsRestriction.iterator(); Iterator<String> listObj = objectsRestriction.iterator();
while ( listObj.hasNext() ) { while ( listObj.hasNext() ) {
subjectsRestriction.add(listObj.next()); subjectsRestriction.add(listObj.next());
} }
if(listBGP.size() > 0) if( listBGP.size() > 0 )
strBGP_Or = listBGP.remove(listBGP.size()-1); strBGP_Or = listBGP.remove( listBGP.size()-1 );
if(stackBGP.size() > 0) if(stackBGP.size() > 0)
stackBGP.remove(stackBGP.size()-1); stackBGP.remove( stackBGP.size()-1 );
visit( c.getDomain() ); c.getDomain().accept( this );
stackBGP.add(strBGP_Or); stackBGP.add( strBGP_Or );
objectsRestriction.clear(); objectsRestriction.clear();
} }
// DONE+TESTED
public void visit( final ClassOccurenceRestriction c ) throws AlignmentException { public void visit( final ClassOccurenceRestriction c ) throws AlignmentException {
if(c.getComparator().getURI().equals( Comparator.EQUAL.getURI())) { String str="";
if( c.getComparator().getURI().equals( Comparator.EQUAL.getURI() ) ) {
nbCardinality = c.getOccurence(); nbCardinality = c.getOccurence();
opOccurence = "="; opOccurence = "=";
} }
if(c.getComparator().getURI().equals( Comparator.GREATER.getURI())) { if( c.getComparator().getURI().equals( Comparator.GREATER.getURI() ) ) {
nbCardinality = c.getOccurence(); nbCardinality = c.getOccurence();
opOccurence = ">"; opOccurence = ">";
} }
if(c.getComparator().getURI().equals( Comparator.LOWER.getURI())) { if( c.getComparator().getURI().equals( Comparator.LOWER.getURI() ) ) {
nbCardinality = c.getOccurence(); nbCardinality = c.getOccurence();
opOccurence = "<"; opOccurence = "<";
} }
visit( c.getRestrictionPath() ); c.getRestrictionPath().accept( this );
Iterator<String> listObj = objectsRestriction.iterator();
if (op == Constructor.COMP) { if ( !objectsRestriction.isEmpty() ) {
strBGP += "FILTER(COUNT(" + listObj.next() + ")" + opOccurence + nbCardinality + ")" +NL; Iterator<String> listObj = objectsRestriction.iterator();
} if (op == Constructor.COMP) {
else{ String tmp = "";
while ( listObj.hasNext() ) { while ( listObj.hasNext() )
strBGP += "FILTER(COUNT(" + listObj.next() + ")" + opOccurence + nbCardinality + ")" +NL; tmp = listObj.next();
str += "FILTER(COUNT(" + tmp + ")" + opOccurence + nbCardinality + ")" +NL;
} }
else{
while ( listObj.hasNext() ) {
str += "FILTER(COUNT(" + listObj.next() + ")" + opOccurence + nbCardinality + ")" +NL;
}
}
while( countInList > listCond.size() )
listCond.add( "" );
if( countInList>0 )
listCond.add( countInList-1, str );
else
listCond.add( countInList, str );
strBGP += str;
} }
if(stackBGP.size() > 0)
stackBGP.remove(stackBGP.size()-1); if( stackBGP.size() > 0 )
stackBGP.remove( stackBGP.size()-1 );
nbCardinality = null; nbCardinality = null;
opOccurence = ""; opOccurence = "";
} }
// DONE public void visit( final PropertyId e ) throws AlignmentException {
public void visit(final PropertyExpression e) throws AlignmentException {
if ( e instanceof PropertyId ) visit( (PropertyId)e );
else if ( e instanceof PropertyConstruction ) visit( (PropertyConstruction)e );
else if ( e instanceof PropertyRestriction ) visit( (PropertyRestriction)e );
else throw new AlignmentException( "Cannot dispatch ClassExpression "+e );
}
// DONE
public void visit(final PropertyId e) throws AlignmentException {
if ( e.getURI() != null ) { if ( e.getURI() != null ) {
String prefix = getPrefixDomain(e.getURI()); String prefix = getPrefixDomain( e.getURI() );
String tag = getPrefixName(e.getURI()); String tag = getPrefixName( e.getURI() );
String shortCut; String shortCut;
if(!prefixList.containsKey(prefix)){ if( !prefixList.containsKey( prefix ) ){
shortCut = getNamespace(); shortCut = getNamespace();
prefixList.put(prefix, shortCut); prefixList.put( prefix, shortCut );
} }
else { else {
shortCut = prefixList.get(prefix); shortCut = prefixList.get( prefix );
} }
String temp = obj; String temp = obj;
if(op == null && valueRestriction != null) if( op == null && valueRestriction != null && !classValueCond )
obj = "\"" + valueRestriction.toString() + "\""; obj = "\"" + valueRestriction.toString() + "\"";
strBGP += sub + " " + shortCut + ":"+ tag + " " + obj + " ." +NL; strBGP += sub + " " + shortCut + ":"+ tag + " " + obj + " ." +NL;
if (op != Constructor.NOT) { if ( op != Constructor.NOT ) {
Stack<String> tempStack = new Stack<String>(); Stack<String> tempStack = new Stack<String>();
if (stackBGP.isEmpty()){ if ( stackBGP.isEmpty() ) {
strBGP_Or = sub + " " + shortCut + ":"+ tag + " " + obj + " ." +NL; strBGP_Or = sub + " " + shortCut + ":"+ tag + " " + obj + " ." +NL;
tempStack.push(strBGP_Or); tempStack.push( strBGP_Or );
} }
else { else {
while (!stackBGP.isEmpty()){ while ( !stackBGP.isEmpty() ){
strBGP_Or = stackBGP.pop(); strBGP_Or = stackBGP.pop();
strBGP_Or += sub + " " + shortCut + ":"+ tag + " " + obj + " ." +NL; strBGP_Or += sub + " " + shortCut + ":"+ tag + " " + obj + " ." +NL;
tempStack.push(strBGP_Or); tempStack.push( strBGP_Or );
} }
} }
while (!tempStack.isEmpty()){ while ( !tempStack.isEmpty() ){
stackBGP.push(tempStack.pop()); stackBGP.push( tempStack.pop() );
} }
} }
obj = temp; obj = temp;
} }
} }
// DONE public void visit( final PropertyConstruction e ) throws AlignmentException {
public void visit(final PropertyConstruction e) throws AlignmentException {
op = e.getOperator(); op = e.getOperator();
if (op == Constructor.OR){ if ( op == Constructor.OR ){
int size = e.getComponents().size(); int size = e.getComponents().size();
Stack<String> tempStack = new Stack<String>(); Stack<String> tempStack = new Stack<String>();
Stack<String> tempResult = new Stack<String>(); Stack<String> tempResult = new Stack<String>();
while(!stackBGP.empty()){ while ( !stackBGP.empty() ) {
tempStack.push(stackBGP.pop()); tempStack.push( stackBGP.pop() );
} }
if(valueRestriction != null) if ( valueRestriction != null && !classValueCond )
obj = "\"" + valueRestriction.toString() + "\""; obj = "\"" + valueRestriction.toString() + "\"";
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
strBGP += "{" +NL; strBGP += "{" +NL;
if(op != null){ if ( op != null ) {
stackOp.push(op); stackOp.push(op);
} }
stackBGP.clear(); stackBGP.clear();
if(!tempStack.empty()){ if ( !tempStack.empty() ) {
for(int i=0; i<tempStack.size(); i++) for( int i=0; i<tempStack.size(); i++ )
stackBGP.push(tempStack.get(i)); stackBGP.push( tempStack.get(i) );
} }
countInList++; countInList++;
visit( re ); re.accept( this );
if(op == Constructor.NOT) if ( op == Constructor.NOT )
stackBGP.clear(); stackBGP.clear();
if(!stackOp.isEmpty()) if( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
while(!stackBGP.empty()){ while( !stackBGP.empty() ){
tempResult.push(stackBGP.pop()); tempResult.push(stackBGP.pop());
} }
size--; size--;
if(size != 0) if( size != 0 )
strBGP += "}" + " UNION " + NL; strBGP += "}" + " UNION " + NL;
else else
strBGP += "}" +NL; strBGP += "}" +NL;
} }
while(!tempResult.empty()){ while( !tempResult.empty() ){
stackBGP.push(tempResult.pop()); stackBGP.push( tempResult.pop() );
} }
objectsRestriction.add(obj); objectsRestriction.add( obj );
} }
else if (op == Constructor.NOT){ else if ( op == Constructor.NOT ) {
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
strBGP += "MINUS {" +NL; strBGP += "MINUS {" +NL;
if(op != null){ if( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
} }
strBGP += "}" +NL; strBGP += "}" +NL;
} }
else if (op == Constructor.COMP){ else if ( op == Constructor.COMP ){
int size = e.getComponents().size(); int size = e.getComponents().size();
String tempSub = sub; String tempSub = sub;
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
writer.print(linePrefix); if ( op != null ) {
if(op != null){
stackOp.push(op); stackOp.push(op);
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if ( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
size--; size--;
if(size != 0){ if ( size != 0 ) {
sub = obj; sub = obj;
if( size == 1 && valueRestriction != null ) { if( size == 1 && valueRestriction != null && !classValueCond ) {
obj = "\"" + valueRestriction.toString() + "\""; obj = "\"" + valueRestriction.toString() + "\"";
} }
else { else {
...@@ -614,25 +593,25 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -614,25 +593,25 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
} }
} }
} }
objectsRestriction.add(obj); objectsRestriction.add( obj );
sub = tempSub; sub = tempSub;
} }
else { else {
int size = e.getComponents().size(); int size = e.getComponents().size();
if(valueRestriction != null) if ( valueRestriction != null && !classValueCond )
obj = "\"" + valueRestriction.toString() + "\""; obj = "\"" + valueRestriction.toString() + "\"";
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
if(op != null){ if ( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if(!stackOp.isEmpty())
op = stackOp.pop(); op = stackOp.pop();
size--; size--;
objectsRestriction.add(obj); objectsRestriction.add( obj );
if(size != 0 && valueRestriction == null){ if( size != 0 && valueRestriction == null ){
if ( blanks ) { if ( blanks ) {
obj = "_:o" + ++count; obj = "_:o" + ++count;
} }
...@@ -642,14 +621,14 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -642,14 +621,14 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
} }
} }
} }
if(stackOp.isEmpty()) { if ( stackOp.isEmpty() ) {
if(op == Constructor.NOT) if ( op == Constructor.NOT )
stackBGP.clear(); stackBGP.clear();
while (!stackBGP.empty()){ while ( !stackBGP.empty() ) {
listBGP.add(stackBGP.pop()); listBGP.add( stackBGP.pop() );
} }
} }
op = null; //op = null;
if ( blanks ) { if ( blanks ) {
obj = "_:o" + ++count; obj = "_:o" + ++count;
} }
...@@ -657,85 +636,66 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -657,85 +636,66 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
obj = "?o" + ++count; obj = "?o" + ++count;
} }
} }
// DONE public void visit( final PropertyValueRestriction c ) throws AlignmentException {
public void visit(final PropertyRestriction e) throws AlignmentException { String str = "";
if ( e instanceof PropertyValueRestriction ) visit( (PropertyValueRestriction)e ); if ( c.getComparator().getURI().equals( Comparator.EQUAL.getURI() ) ) {
else if ( e instanceof PropertyDomainRestriction ) visit( (PropertyDomainRestriction)e );
else if ( e instanceof PropertyTypeRestriction ) visit( (PropertyTypeRestriction)e );
else throw new AlignmentException( "Cannot dispatch ClassExpression "+e );
//resetVariablesName();
}
// DONE
public void visit(final PropertyValueRestriction c) throws AlignmentException {
if(c.getComparator().getURI().equals( Comparator.EQUAL.getURI())){
strBGP += sub + " ?p "; strBGP += sub + " ?p ";
strBGP_Or = sub + " ?p "; strBGP_Or = sub + " ?p ";
visit( c.getValue() ); c.getValue().accept( this );
strBGP += "\"" + value + "\" ." + NL; strBGP += "\"" + value + "\" ." + NL;
strBGP_Or += "\"" + value + "\" ." + NL; strBGP_Or += "\"" + value + "\" ." + NL;
} }
else if(c.getComparator().getURI().equals( Comparator.GREATER.getURI())){ else if ( c.getComparator().getURI().equals( Comparator.GREATER.getURI() ) ) {
strBGP += sub + " ?p " + obj + " ." + NL; strBGP += sub + " ?p " + obj + " ." + NL;
strBGP_Or = sub + " ?p " + obj + " ." + NL; strBGP_Or = sub + " ?p " + obj + " ." + NL;
String str = "FILTER (xsd:" + uriType + "(" + obj + ") > "; str = "FILTER (xsd:" + uriType + "(" + obj + ") > ";
flagRestriction = 1; flagRestriction = 1;
visit( c.getValue() ); c.getValue().accept( this );
flagRestriction = 0; flagRestriction = 0;
str += "\"" + value + "\")" + NL; str += "\"" + value + "\")" + NL;
while(countInList > listCond.size())
listCond.add("");
if(countInList>0)
listCond.add(countInList-1, str);
else
listCond.add(countInList, str);
strBGP += str;
} }
else if(c.getComparator().getURI().equals( Comparator.LOWER.getURI())){ else if ( c.getComparator().getURI().equals( Comparator.LOWER.getURI() ) ) {
strBGP += sub + " ?p " + obj + " ." + NL; strBGP += sub + " ?p " + obj + " ." + NL;
strBGP_Or = sub + " ?p " + obj + " ." + NL; strBGP_Or = sub + " ?p " + obj + " ." + NL;
String str = "FILTER (xsd:" + uriType + "(" + obj + ") < "; str = "FILTER (xsd:" + uriType + "(" + obj + ") < ";
flagRestriction = 1; flagRestriction = 1;
visit( c.getValue() ); c.getValue().accept( this );
flagRestriction = 0; flagRestriction = 0;
str += "\"" + value + "\")" + NL; str += "\"" + value + "\")" + NL;
while(countInList > listCond.size())
listCond.add("");
if(countInList>0)
listCond.add(countInList-1, str);
else
listCond.add(countInList, str);
strBGP += str;
} }
while ( countInList > listCond.size() )
listCond.add( "" );
if ( countInList>0 )
listCond.add( countInList-1, str );
else
listCond.add( countInList, str );
strBGP += str;
stackBGP.push(strBGP_Or); stackBGP.push(strBGP_Or);
//else throw new AlignmentException( "Cannot dispatch Comparator "+c ); //else throw new AlignmentException( "Cannot dispatch Comparator "+c );
} }
// DONE public void visit( final PropertyDomainRestriction c ) throws AlignmentException {
public void visit(final PropertyDomainRestriction c) throws AlignmentException {
flagRestriction = 1; flagRestriction = 1;
strBGP += sub + " ?p " + obj + " ." + NL; strBGP += sub + " ?p " + obj + " ." + NL;
strBGP_Or = sub + " ?p " + obj + " ." + NL; strBGP_Or = sub + " ?p " + obj + " ." + NL;
visit( c.getDomain() ); c.getDomain().accept( this );
flagRestriction = 0; flagRestriction = 0;
} }
// DONE public void visit( final PropertyTypeRestriction c ) throws AlignmentException {
public void visit(final PropertyTypeRestriction c) throws AlignmentException {
String str = "FILTER (datatype(" + objectsRestriction + ") = "; String str = "FILTER (datatype(" + objectsRestriction + ") = ";
if ( !objectsRestriction.isEmpty() ) { if ( !objectsRestriction.isEmpty() ) {
Iterator<String> listObj = objectsRestriction.iterator(); Iterator<String> listObj = objectsRestriction.iterator();
int size = objectsRestriction.size(); int size = objectsRestriction.size();
if (size > 0) { if ( size > 0 ) {
increaseIndent(); increaseIndent();
str = "FILTER (datatype(" + listObj.next() + ") = "; str = "FILTER (datatype(" + listObj.next() + ") = ";
visit( c.getType() ); visit( c.getType() );
...@@ -747,55 +707,46 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -747,55 +707,46 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
str += "xsd:" + datatype; str += "xsd:" + datatype;
} }
str += ")" + NL; str += ")" + NL;
while(countInList > listCond.size()) while ( countInList > listCond.size() )
listCond.add(""); listCond.add( "" );
if(countInList>0) if( countInList>0 )
listCond.add(countInList-1, str); listCond.add( countInList-1, str );
else else
listCond.add(countInList, str); listCond.add( countInList, str );
strBGP += str; strBGP += str;
} }
objectsRestriction.clear(); objectsRestriction.clear();
} }
// DONE
public void visit( final RelationExpression e ) throws AlignmentException {
if ( e instanceof RelationId ) visit( (RelationId)e );
else if ( e instanceof RelationRestriction ) visit( (RelationRestriction)e );
else if ( e instanceof RelationConstruction ) visit( (RelationConstruction)e );
else throw new AlignmentException( "Cannot dispatch ClassExpression "+e );
}
// DONE
public void visit( final RelationId e ) throws AlignmentException { public void visit( final RelationId e ) throws AlignmentException {
if ( e.getURI() != null ) { if ( e.getURI() != null ) {
String prefix = getPrefixDomain(e.getURI()); String prefix = getPrefixDomain(e.getURI());
String tag = getPrefixName(e.getURI()); String tag = getPrefixName(e.getURI());
String shortCut; String shortCut;
if(!prefixList.containsKey(prefix)){ if ( !prefixList.containsKey(prefix) ) {
shortCut = getNamespace(); shortCut = getNamespace();
prefixList.put(prefix, shortCut); prefixList.put( prefix, shortCut );
} }
else { else {
shortCut = prefixList.get(prefix); shortCut = prefixList.get( prefix );
} }
strBGP += sub + " " + shortCut + ":"+ tag + ""; strBGP += sub + " " + shortCut + ":"+ tag + "";
String str = sub + " " + shortCut + ":"+ tag + ""; String str = sub + " " + shortCut + ":"+ tag + "";
if (op == Constructor.TRANSITIVE){ if ( op == Constructor.TRANSITIVE ) {
strBGP += "*"; strBGP += "*";
str += "*"; str += "*";
} }
if(op == null && valueRestriction != null) if ( op == null && valueRestriction != null && !classValueCond )
obj = valueRestriction.toString(); obj = valueRestriction.toString();
strBGP += " " + obj + " ." + NL; strBGP += " " + obj + " ." + NL;
str += " " + obj + " ." + NL; str += " " + obj + " ." + NL;
if (op != Constructor.NOT) { if ( op != Constructor.NOT ) {
Stack<String> tempStack = new Stack<String>(); Stack<String> tempStack = new Stack<String>();
if (stackBGP.isEmpty()){ if ( stackBGP.isEmpty() ){
strBGP_Or = str; strBGP_Or = str;
tempStack.push(strBGP_Or); tempStack.push(strBGP_Or);
} }
...@@ -803,36 +754,35 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -803,36 +754,35 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
while (!stackBGP.isEmpty()){ while (!stackBGP.isEmpty()){
strBGP_Or = stackBGP.pop(); strBGP_Or = stackBGP.pop();
strBGP_Or += str; strBGP_Or += str;
tempStack.push(strBGP_Or); tempStack.push( strBGP_Or );
} }
} }
while (!tempStack.isEmpty()){ while ( !tempStack.isEmpty() ) {
stackBGP.push(tempStack.pop()); stackBGP.push( tempStack.pop() );
} }
} }
} }
} }
// DONE
public void visit( final RelationConstruction e ) throws AlignmentException { public void visit( final RelationConstruction e ) throws AlignmentException {
op = e.getOperator(); op = e.getOperator();
if (op == Constructor.OR){ if ( op == Constructor.OR ) {
int size = e.getComponents().size(); int size = e.getComponents().size();
Stack<String> tempStack = new Stack<String>(); Stack<String> tempStack = new Stack<String>();
Stack<String> tempResult = new Stack<String>(); Stack<String> tempResult = new Stack<String>();
while(!stackBGP.empty()){ while ( !stackBGP.empty() ) {
tempStack.push(stackBGP.pop()); tempStack.push(stackBGP.pop());
} }
if(valueRestriction != null) if ( valueRestriction != null && !classValueCond )
obj = valueRestriction.toString(); obj = valueRestriction.toString();
String temp = obj; String temp = obj;
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
writer.print(linePrefix); writer.print(linePrefix);
strBGP += "{" + NL; strBGP += "{" + NL;
if(op != null){ if ( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
stackBGP.clear(); stackBGP.clear();
if(!tempStack.empty()){ if(!tempStack.empty()){
...@@ -840,63 +790,64 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -840,63 +790,64 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
stackBGP.push(tempStack.get(i)); stackBGP.push(tempStack.get(i));
} }
countInList++; countInList++;
visit( re ); re.accept( this );
if(op == Constructor.NOT){ if ( op == Constructor.NOT ) {
stackBGP.clear(); stackBGP.clear();
} }
if(!stackOp.isEmpty()) if ( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
while(!stackBGP.empty()){ while ( !stackBGP.empty() ) {
tempResult.push(stackBGP.pop()); tempResult.push( stackBGP.pop() );
} }
obj = temp; obj = temp;
size--; size--;
if(size != 0) if ( size != 0 )
strBGP += "}" + "UNION " + NL; strBGP += "}" + "UNION " + NL;
else else
strBGP += "}" + NL; strBGP += "}" + NL;
} }
while(!tempResult.empty()){ while ( !tempResult.empty() ) {
stackBGP.push(tempResult.pop()); stackBGP.push( tempResult.pop() );
} }
objectsRestriction.add(obj); objectsRestriction.add( obj );
} }
else if (op == Constructor.NOT){ else if ( op == Constructor.NOT ) {
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
strBGP += "MINUS {" + NL; strBGP += "MINUS {" + NL;
if(op != null){ if ( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
strBGP += "}" + NL; strBGP += "}" + NL;
} }
} }
else if (op == Constructor.COMP){ else if ( op == Constructor.COMP ) {
int size = e.getComponents().size(); int size = e.getComponents().size();
String temp = sub; String temp = sub;
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
if(op != null){ if ( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
size--; size--;
if(size != 0) { if( size != 0 ) {
sub = obj; sub = obj;
if(size == 1 && valueRestriction != null) if ( size == 1 && valueRestriction != null && !classValueCond ) {
obj = valueRestriction.toString(); obj = valueRestriction.toString();
}
else { else {
if ( blanks ) { if ( blanks ) {
obj = "_:o" + ++count; obj = "_:o" + ++count;
} }
else { else {
obj = "?o" + ++count; obj = "?o" + ++count;
objectsRestriction.add(obj); }
} objectsRestriction.add( obj );
} }
} }
...@@ -904,44 +855,43 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -904,44 +855,43 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
sub = temp; sub = temp;
} }
else if (op == Constructor.INVERSE){ else if ( op == Constructor.INVERSE ) {
String tempSub = sub; String tempSub = sub;
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
writer.print(linePrefix);
String temp = sub; String temp = sub;
sub = obj; sub = obj;
obj = temp; obj = temp;
if(op != null){ if( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if ( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
sub = tempSub; sub = tempSub;
} }
} }
else if (op == Constructor.SYMMETRIC){ else if ( op == Constructor.SYMMETRIC ) {
String tempSub = sub; String tempSub = sub;
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
strBGP += "{" + NL; strBGP += "{" + NL;
if(op != null){ if ( op != null ) {
stackOp.push(op); stackOp.push(op);
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
objectsRestriction.add(obj); objectsRestriction.add( obj );
String temp = sub; String temp = sub;
sub = obj; sub = obj;
obj = temp; obj = temp;
strBGP += "} UNION {" + NL; strBGP += "} UNION {" + NL;
if(op != null){ if( op != null ) {
stackOp.push(op); stackOp.push(op);
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if(!stackOp.isEmpty())
op = stackOp.pop(); op = stackOp.pop();
objectsRestriction.add(obj); objectsRestriction.add( obj );
strBGP +="}" + NL; strBGP +="}" + NL;
} }
...@@ -952,19 +902,19 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -952,19 +902,19 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
if(op != null){ if(op != null){
stackOp.push(op); stackOp.push(op);
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if(!stackOp.isEmpty())
op = stackOp.pop(); op = stackOp.pop();
} }
} }
else if (op == Constructor.REFLEXIVE){ else if ( op == Constructor.REFLEXIVE ) {
String str = obj; String str = obj;
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
if(op != null){ if ( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
obj = sub; obj = sub;
visit( re ); re.accept( this );
obj = str; obj = str;
if(!stackOp.isEmpty()) if(!stackOp.isEmpty())
op = stackOp.pop(); op = stackOp.pop();
...@@ -973,19 +923,19 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -973,19 +923,19 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
else { else {
int size = e.getComponents().size(); int size = e.getComponents().size();
if(valueRestriction != null) if ( valueRestriction != null && !classValueCond )
obj = valueRestriction.toString(); obj = valueRestriction.toString();
for ( final PathExpression re : e.getComponents() ) { for ( final PathExpression re : e.getComponents() ) {
if(op != null){ if ( op != null ) {
stackOp.push(op); stackOp.push( op );
} }
visit( re ); re.accept( this );
if(!stackOp.isEmpty()) if ( !stackOp.isEmpty() )
op = stackOp.pop(); op = stackOp.pop();
size--; size--;
objectsRestriction.add(obj); objectsRestriction.add( obj );
if(size != 0 && valueRestriction == null){ if ( size != 0 && valueRestriction == null ) {
if ( blanks ) { if ( blanks ) {
obj = "_:o" + ++count; obj = "_:o" + ++count;
} }
...@@ -996,14 +946,14 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -996,14 +946,14 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
} }
} }
if(stackOp.isEmpty()) { if ( stackOp.isEmpty() ) {
if(op == Constructor.NOT) if ( op == Constructor.NOT )
stackBGP.clear(); stackBGP.clear();
while (!stackBGP.empty()){ while ( !stackBGP.empty() ) {
listBGP.add(stackBGP.pop()); listBGP.add(stackBGP.pop() );
} }
} }
op = null; //op = null;
if ( blanks ) { if ( blanks ) {
obj = "_:o" + ++count; obj = "_:o" + ++count;
} }
...@@ -1011,105 +961,69 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito ...@@ -1011,105 +961,69 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
obj = "?o" + ++count; obj = "?o" + ++count;
} }
} }
// DONE
public void visit( final RelationRestriction e ) throws AlignmentException {
if ( e instanceof RelationCoDomainRestriction ) visit( (RelationCoDomainRestriction)e );
else if ( e instanceof RelationDomainRestriction ) visit( (RelationDomainRestriction)e );
else throw new AlignmentException( "Cannot dispatch ClassExpression "+e );
//resetVariablesName();
}
// DONE
public void visit(final RelationCoDomainRestriction c) throws AlignmentException { public void visit(final RelationCoDomainRestriction c) throws AlignmentException {
flagRestriction = 1; flagRestriction = 1;
visit( c.getCoDomain() ); c.getCoDomain().accept( this );
flagRestriction = 0; flagRestriction = 0;
} }
// DONE
public void visit(final RelationDomainRestriction c) throws AlignmentException { public void visit(final RelationDomainRestriction c) throws AlignmentException {
flagRestriction = 1; flagRestriction = 1;
strBGP += sub + " ?p " + obj + " ." + NL; strBGP += sub + " ?p " + obj + " ." + NL;
visit( c.getDomain() ); c.getDomain().accept( this );
flagRestriction = 0; flagRestriction = 0;
} }
// DONE
public void visit( final InstanceExpression e ) throws AlignmentException {
if ( e instanceof InstanceId ) visit( (InstanceId)e );
else throw new AlignmentException( "Cannot handle InstanceExpression "+e );
}
// DONE+TESTED
public void visit( final InstanceId e ) throws AlignmentException { public void visit( final InstanceId e ) throws AlignmentException {
if ( e.getURI() != null ) { if ( e.getURI() != null ) {
String prefix = getPrefixDomain(e.getURI()); String prefix = getPrefixDomain( e.getURI() );
String tag = getPrefixName(e.getURI()); String tag = getPrefixName( e.getURI() );
String shortCut; String shortCut;
if(!prefixList.containsKey(prefix)){ if ( !prefixList.containsKey( prefix) ){
shortCut = getNamespace(); shortCut = getNamespace();
prefixList.put(prefix, shortCut); prefixList.put( prefix, shortCut );
} }
else { else {
shortCut = prefixList.get(prefix); shortCut = prefixList.get( prefix );
} }
if(flagRestriction != 1) if ( flagRestriction != 1 )
strBGP += shortCut + ":"+ tag + " ?p ?o1 ." +NL; strBGP += shortCut + ":"+ tag + " ?p ?o1 ." +NL;
else else
instance = shortCut + ":"+ tag; instance = shortCut + ":"+ tag;
} }
} }
// DONE+TESTED
public void visit( final ValueExpression e ) throws AlignmentException {
if ( e instanceof InstanceExpression )visit( (InstanceExpression)e );
else if ( e instanceof PathExpression ) {
if(isValueRestriction)
return;
else
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 { public void visit( final Value e ) throws AlignmentException {
if (e.getType() != null) { if (e.getType() != null) {
String str = e.getType().toString(); String str = e.getType().toString();
int index; int index;
if (str.contains("#")) if ( str.contains("#") )
index = str.lastIndexOf("#"); index = str.lastIndexOf("#");
else else
index = str.lastIndexOf("/"); index = str.lastIndexOf("/");
uriType = str.substring(0, index+1); uriType = str.substring( index+1 );
} }
value = e.getValue(); value = e.getValue();
} }
public void visit( final Apply e ) throws AlignmentException { public void visit( final Apply e ) throws AlignmentException {}
} public void visit( final Transformation transf ) throws AlignmentException {}
public void visit( final Transformation transf ) throws AlignmentException {
}
// DONE
public void visit( final Datatype e ) throws AlignmentException { public void visit( final Datatype e ) throws AlignmentException {
int index; int index;
if (e.getType().contains("#")) if ( e.getType().contains("#") )
index = e.getType().lastIndexOf("#"); index = e.getType().lastIndexOf("#");
else else
index = e.getType().lastIndexOf("/"); index = e.getType().lastIndexOf("/");
datatype = e.getType().substring(index+1); datatype = e.getType().substring( index+1 );
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment