Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented predicateMap #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/gr/seab/r2rml/beans/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ public void createTriples(MappingDocument mappingDocument) {
}
}

for (String predicate : predicateObjectMap.getPredicates()) {
for (Template predicate : predicateObjectMap.getPredicates()) {

Property p = resultModel.createProperty(predicate);
Property p = resultModel.createProperty(util.fillTemplate(predicate, rs, encodeURLs));

if (objectTemplate != null && objectTemplate.getTermType() != TermType.AUTO) {
//Literal o = resultModel.createLiteral(u.fillTemplate(predicateObjectMap.getObjectTemplate(), rs));
Expand Down
48 changes: 39 additions & 9 deletions src/main/java/gr/seab/r2rml/beans/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,20 @@ public ArrayList<PredicateObjectMap> createPredicateObjectMapsForResource(Resour
PredicateObjectMap predicateObjectMap = new PredicateObjectMap();

NodeIterator iterPredicate = mapModel.listObjectsOfProperty(rnPredicateObject.asResource(), mapModel.getProperty(rrNs + "predicate"));
ArrayList<String> predicates = new ArrayList<String>();
ArrayList<Template> predicates = new ArrayList<Template>();
while (iterPredicate.hasNext()) { //can return more than 1
RDFNode rnPredicate = iterPredicate.next();
if (verbose) log.info("Predicate is: " + rnPredicate.asResource().getURI());
predicates.add(rnPredicate.asResource().getURI());
log.info("Found predicate: " + rnPredicate.toString());
if (rnPredicate.isLiteral()) {
log.info("Adding predicate map constant: " + rnPredicate.asLiteral().toString() + ". Treating it as a template with no fields.");
Template template = new Template(rnPredicate.asLiteral(), TermType.LITERAL, baseNs, resultModel);
predicates.add(template);
} else {
log.info("Adding predicate map constant: " + rnPredicate.asNode().toString() + ". Treating it as a template with no fields.");
Template template = new Template(rnPredicate.asNode().toString(), TermType.IRI, baseNs, resultModel);
predicates.add(template);
}
}

NodeIterator iterPredicateMap = mapModel.listObjectsOfProperty(rnPredicateObject.asResource(), mapModel.getProperty(rrNs + "predicateMap"));
Expand All @@ -294,14 +303,35 @@ public ArrayList<PredicateObjectMap> createPredicateObjectMapsForResource(Resour
while (iterConstant.hasNext()) {
RDFNode rnConstant = iterConstant.next();

if (rnConstant.isLiteral()) {
log.info("Adding predicate map constant literal: " + rnConstant.asNode().toString() + ".");
predicates.add(rnConstant.asLiteral().getString());
} else {
log.info("Adding predicate map constant uri: " + rnConstant.asNode().toString() + ".");
predicates.add(rnConstant.asResource().getURI());
}
if (rnConstant.isLiteral()) {
log.info("Adding predicate map constant: " + rnConstant.asLiteral().toString() + ". Treating it as a template with no fields.");
Template template = new Template(rnConstant.asLiteral(), TermType.LITERAL, baseNs, resultModel);
predicates.add(template);
} else {
log.info("Adding predicate map constant: " + rnConstant.asNode().toString() + ". Treating it as a template with no fields.");
Template template = new Template(rnConstant.asNode().toString(), TermType.IRI, baseNs, resultModel);
predicates.add(template);
}
}
NodeIterator iterTemplate = mapModel.listObjectsOfProperty(rnPredicateMap.asResource(), mapModel.getProperty(rrNs + "template"));
while (iterTemplate.hasNext()) { //should return only 1
RDFNode rnTemplate = iterTemplate.next();

if (rnTemplate.isLiteral()) {
log.info("Processing predicate map template: " + rnTemplate.asLiteral().getString());
Template template = new Template(rnTemplate.asLiteral(), TermType.LITERAL, baseNs, resultModel);
predicates.add(template);

} else {
log.info("Processing predicate map template: " + rnTemplate.asNode().toString());
Template template = new Template(rnTemplate.asNode().toString(), TermType.IRI, baseNs, resultModel);
predicates.add(template);

}
//predicateObjectMap.setObjectColumn(predicateObjectMap.getObjectTemplate().getFields().get(0));
//System.out.println("added objectQuery " + "SELECT " + predicateObjectMap.getObjectTemplate().getFields().get(0) + " FROM " + mappingDocument.findLogicalTableMappingByUri(r.getURI()).getView().getQuery().getTables().get(0).getName());
//System.out.println("added objectTemplate " + rnTemplate.asLiteral().toString());
}
}
predicateObjectMap.setPredicates(predicates);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gr/seab/r2rml/beans/UtilImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ public String md5(LogicalTableMapping logicalTableMapping) {
s += predicateObjectMap.getObjectColumn();
}

for (String predicate : predicateObjectMap.getPredicates()) {
s += predicate;
for (Template predicate : predicateObjectMap.getPredicates()) {
s += predicate.getText();
}

s += predicateObjectMap.getRefObjectMap() != null? predicateObjectMap.getRefObjectMap().getParentTriplesMapUri() : "null";
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gr/seab/r2rml/entities/PredicateObjectMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PredicateObjectMap {
/**
* The predicate value(s).
*/
private ArrayList<String> predicates;
private ArrayList<Template> predicates;

/**
* Holds the template through which the objects will be generated.
Expand Down Expand Up @@ -44,13 +44,13 @@ public PredicateObjectMap() {
/**
* @return the predicates
*/
public ArrayList<String> getPredicates() {
public ArrayList<Template> getPredicates() {
return predicates;
}
/**
* @param predicates the predicates to set
*/
public void setPredicates(ArrayList<String> predicates) {
public void setPredicates(ArrayList<Template> predicates) {
this.predicates = predicates;
}
/**
Expand Down