private String generateSubjectMapRDF( SubjectMap subjMap, Set<String> existingTopRowTriples, Map<String, String> columnValues) throws ValueNotFoundKarmaException, NoValueFoundInNodeException { // Generate URI for subject String uri = ""; if (subjMap.isBlankNode()) { uri = getBlankNodeUri(subjMap.getId(), columnValues) .replaceAll(" ", "") .replaceAll("[,`']", "_"); } else uri = getTemplateTermSetPopulatedWithValues(columnValues, subjMap.getTemplate()) .replaceAll(" ", "") .replaceAll("[,`']", "_"); // Generate triples for specifying the types for (TemplateTermSet typeTerm : subjMap.getRdfsType()) { String typeUri = getTemplateTermSetPopulatedWithValues(columnValues, typeTerm); String triple = constructTripleWithURIObject(uri, Uris.RDF_TYPE_URI, typeUri); if (!existingTopRowTriples.contains(triple)) { existingTopRowTriples.add(triple); outWriter.println(triple); } } return uri; }
private void generatePropertyForPredObjMap( PredicateObjectMap pom, Map<String, String> columnValues, Set<String> predicatesCovered, Set<String> existingTopRowTriples, String hNodeId, Map<String, ReportMessage> predicatesFailed) { // Generate subject RDF SubjectMap subjMap = pom.getTriplesMap().getSubject(); String subjUri = ""; try { subjUri = generateSubjectMapRDF(subjMap, existingTopRowTriples, columnValues); } catch (ValueNotFoundKarmaException ve) { ReportMessage msg = createReportMessage( "Could not generate subject's RDF and URI for <i>predicate:" + pom.getPredicate() .getTemplate() .toString() .replaceAll("<", "{") .replaceAll(">", "}") + ", subject node: " + subjMap.getId() + "</i>", ve, this.factory.getHNode(hNodeId).getColumnName()); predicatesFailed.put(pom.getPredicate().getId(), msg); return; } catch (NoValueFoundInNodeException e) { logger.debug("No value found in a node required to generate subject's RDF or URI."); } // Generate the predicate RDF String predicateUri = ""; try { predicateUri = getTemplateTermSetPopulatedWithValues(columnValues, pom.getPredicate().getTemplate()) .replaceAll(" ", ""); } catch (ValueNotFoundKarmaException ve) { ReportMessage msg = createReportMessage( "Could not generate predicate's URI for <i>predicate:" + pom.getPredicate() .getTemplate() .toString() .replaceAll("<", "{") .replaceAll(">", "}") + ", subject node: " + subjMap.getId() + "</i>", ve, this.factory.getHNode(hNodeId).getColumnName()); predicatesFailed.put(pom.getPredicate().getId(), msg); return; } catch (NoValueFoundInNodeException e) { logger.debug("No value found in a node required to generate predicate's URI."); } // Object property if (pom.getObject().hasRefObjectMap()) { // Generate the object URI TriplesMap objPropertyObjectTriplesMap = pom.getObject().getRefObjectMap().getParentTriplesMap(); String objUri = ""; try { objUri = generateSubjectMapRDF( objPropertyObjectTriplesMap.getSubject(), existingTopRowTriples, columnValues); } catch (ValueNotFoundKarmaException ve) { ReportMessage msg = createReportMessage( "Could not generate object's URI for <i>predicate:" + pom.getPredicate() .getTemplate() .toString() .replaceAll("<", "{") .replaceAll(">", "}") + ", subject node: " + pom.getTriplesMap().getSubject().getId() + "</i>", ve, this.factory.getHNode(hNodeId).getColumnName()); predicatesFailed.put(pom.getPredicate().getId(), msg); return; } catch (NoValueFoundInNodeException e) { logger.debug("No value found in a node required to generate object's URI for a predicate."); } String triple = constructTripleWithURIObject(subjUri, predicateUri, objUri); if (!existingTopRowTriples.contains(triple)) { outWriter.println(triple); existingTopRowTriples.add(triple); } } // Data Property else { // Get the value String value = ""; try { value = getTemplateTermSetPopulatedWithValues(columnValues, pom.getObject().getTemplate()); if (value == null || value.trim().equals("")) return; } catch (ValueNotFoundKarmaException ve) { ReportMessage msg = createReportMessage( "Could not retrieve value for the <i>predicate:" + pom.getPredicate() .getTemplate() .toString() .replaceAll("<", "{") .replaceAll(">", "}") + ", subject node: " + subjMap.getId() + "</i>", ve, this.factory.getHNode(hNodeId).getColumnName()); predicatesFailed.put(pom.getPredicate().getId(), msg); return; } catch (NoValueFoundInNodeException e) { logger.debug("No value found in a node required to generate value for a predicate."); } String triple = constructTripleWithLiteralObject(subjUri, predicateUri, value, ""); if (!existingTopRowTriples.contains(triple)) { existingTopRowTriples.add(triple); outWriter.println(triple); } } predicatesCovered.add(pom.getPredicate().getId()); if (predicatesFailed.containsKey(pom.getPredicate().getId())) predicatesFailed.remove(pom.getPredicate().getId()); }