Browse Source

fix in preview

Ademar Crotti Junior 4 years ago
parent
commit
8c4484fffc
2 changed files with 26 additions and 16 deletions
  1. 7 7
      src/r2rml/model/PredicateMap.java
  2. 19 9
      src/r2rml/model/R2RMLUtil.java

+ 7 - 7
src/r2rml/model/PredicateMap.java

@@ -28,8 +28,8 @@ public class PredicateMap extends TermMap {
 	@Override
 	public boolean preProcessAndValidate() {
 		logger.info("Processing PredicateMap " + description);
-		
-		if(!super.preProcessAndValidate())
+
+		if (!super.preProcessAndValidate())
 			return false;
 
 		return true;
@@ -37,9 +37,9 @@ public class PredicateMap extends TermMap {
 
 	@Override
 	protected RDFNode distillConstant(RDFNode node) {
-		// If the constant-valued term map is a subject map, predicate map or graph map, 
+		// If the constant-valued term map is a subject map, predicate map or graph map,
 		// then its constant value must be an IRI.
-		if(!node.isURIResource()) {
+		if (!node.isURIResource()) {
 			logger.error("Constant for PredicateMap must be an IRI.");
 			logger.error(description);
 			return null;
@@ -50,12 +50,12 @@ public class PredicateMap extends TermMap {
 
 	@Override
 	protected boolean isChosenTermTypeValid() {
-		if(!isTermTypeIRI()) {
+		if (!isTermTypeIRI()) {
 			logger.error("TermType for PredicateMap must be rr:IRI.");
 			logger.error(description);
 			return false;
 		}
-		
+
 		return true;
 	}
 
@@ -63,7 +63,7 @@ public class PredicateMap extends TermMap {
 	protected Resource inferTermType() {
 		return R2RML.IRI;
 	}
-	
+
 	public Property generateRDFTerm(Row row) throws R2RMLException {
 		// PredicateMaps generate terms that are properties.
 		String uri = super.generateRDFTerm(row).asResource().getURI();

+ 19 - 9
src/r2rml/model/R2RMLUtil.java

@@ -9,6 +9,7 @@ import java.util.Map;
 
 import org.apache.jena.rdf.model.RDFNode;
 import org.apache.log4j.Logger;
+import org.h2.util.StringUtils;
 
 public class R2RMLUtil {
 
@@ -22,8 +23,7 @@ public class R2RMLUtil {
 	}
 
 	/**
-	 * Utility function to check whether the string denoting a column name is
-	 * valid
+	 * Utility function to check whether the string denoting a column name is valid
 	 * 
 	 * @param columnName
 	 * @return True if a valid column name
@@ -42,8 +42,7 @@ public class R2RMLUtil {
 		String pquery = parent.getLogicalTable().generateQuery();
 
 		if (!cquery.equals(pquery) && joins.isEmpty()) {
-			logger.error(
-					"If the child query and parent query of a referencing object map are not identical, then the referencing object map must have at least one join condition.");
+			logger.error("If the child query and parent query of a referencing object map are not identical, then the referencing object map must have at least one join condition.");
 			return null;
 		}
 
@@ -64,15 +63,26 @@ public class R2RMLUtil {
 		return query;
 	}
 
-	public static String createJointQueryPreview(TriplesMap triplesMap, TriplesMap ptm, List<Join> joins,
-			Map<String, Object> data) {
-		
+	public static String createJointQueryPreview(TriplesMap triplesMap, TriplesMap ptm, List<Join> joins, Map<String, Object> data) {
+
 		String query = createJointQuery(triplesMap, ptm, joins);
 
 		for (Join join : joins) {
-			query += " AND child." + join.getChild() + "=" + data.get(join.getChild());
+			Object value = data.get(join.getChild());
+			boolean isNumber = false;
+			try {
+				if (StringUtils.isNumber(String.valueOf(value))) {
+					isNumber = true;
+				}
+			} catch (Exception e) {
+
+			}
+			if (isNumber)
+				query += " AND child." + join.getChild() + "=" + data.get(join.getChild());
+			else
+				query += " AND child." + join.getChild() + "='" + data.get(join.getChild()) + "'";
 		}
-		
+
 		return query;
 	}