/*** * Sets the current mapping to the input. Note, if the current mapping is * set, this means that this dialog is "updating" a mapping, and not * creating a new one. */ public void setMapping(SQLPPTriplesMap mapping) { this.mapping = mapping; cmdInsertMapping.setText("Update"); txtMappingID.setText(mapping.getId()); OBDASQLQuery sourceQuery = mapping.getSourceQuery(); String srcQuery = SourceQueryRenderer.encode(sourceQuery); txtSourceQuery.setText(srcQuery); ImmutableList<TargetAtom> targetQuery = mapping.getTargetAtoms(); String trgQuery = TargetQueryRenderer.encode(targetQuery, prefixManager); txtTargetQuery.setText(trgQuery); } }
private ImmutableList<SQLPPTriplesMap> splitMappingAxiom(SQLPPTriplesMap mappingAxiom, String delimiterSubstring) { Multimap<ImmutableFunctionalTerm, TargetAtom> subjectTermToTargetTriples = ArrayListMultimap.create(); for (TargetAtom targetTriple : mappingAxiom.getTargetAtoms()) { ImmutableFunctionalTerm subjectTerm = getFirstFunctionalTerm(targetTriple) .orElseThrow(() -> new IllegalStateException("Invalid OBDA mapping")); subjectTermToTargetTriples.put(subjectTerm, targetTriple); } // If the partition per target triple subject is non trivial if (subjectTermToTargetTriples.size() > 1) { // Create ids for the new mapping axioms Map<ImmutableFunctionalTerm, String> subjectTermToMappingIndex = new HashMap<>(); int i = 1; for (ImmutableFunctionalTerm subjectTerm : subjectTermToTargetTriples.keySet()) { subjectTermToMappingIndex.put(subjectTerm, mappingAxiom.getId() + delimiterSubstring + i); i++; } // Generate one mapping axiom per subject return subjectTermToTargetTriples.asMap().entrySet().stream() .map(e -> mappingAxiom.extractPPMappingAssertions( subjectTermToMappingIndex.get(e.getKey()), ImmutableList.copyOf(e.getValue()))) .collect(ImmutableCollectors.toList()); } return ImmutableList.of(mappingAxiom); }
@Override public String getProvenanceInfo() { String info = "id: " + triplesMap.getId(); info += "\ntarget atom: " + targetAtom.toString(); info += "\nsource query: " + triplesMap.getSourceQuery(); return info; }
@Override public boolean match(SQLPPTriplesMap object) { ImmutableList<TargetAtom> atoms = object.getTargetAtoms(); boolean isMatch = false; for (String keyword : vecKeyword) { for (TargetAtom atom : atoms) { isMatch = isMatch || TreeModelTools.match(keyword.trim(), atom); } if (isMatch) { break; // end loop if a match is found! } } return bNegation != isMatch; }
OBDASQLQuery sourceQuery = mappingAxiom.getSourceQuery(); for (ImmutableFunctionalTerm atom : mappingAxiom.getTargetAtoms()) { PPMappingAssertionProvenance provenance = mappingAxiom.getMappingAssertionProvenance(atom); try { errorMessages.add("Error: " + e.getMessage() + " \nProblem location: source query of triplesMap \n[" + mappingAxiom.getTriplesMapProvenance().getProvenanceInfo() + "]");
public void updateMappingId(String formerMappingId, String newMappingId) throws DuplicateMappingException { //if the id are the same no need to update the mapping if(!formerMappingId.equals(newMappingId)) { SQLPPTriplesMap formerTriplesMap = getTriplesMap(formerMappingId); if (formerTriplesMap != null) { SQLPPTriplesMap newTriplesMap = new OntopNativeSQLPPTriplesMap(newMappingId, formerTriplesMap.getSourceQuery(), formerTriplesMap.getTargetAtoms()); addTriplesMap(newTriplesMap, false); triplesMapMap.remove(formerMappingId); fireMappingUpdated(); } } }
private String getSplitMappingAxiomIdDelimiterSubstring(List<SQLPPTriplesMap> mappingAxioms) { String delimiterSubstring = ""; boolean matched; do { delimiterSubstring += "_"; Pattern pattern = Pattern.compile(delimiterSubstring + "(\\d)*$"); matched = mappingAxioms.stream() .anyMatch(a -> pattern.matcher(a.getId()).matches()); } while (matched); return delimiterSubstring; }
public void run(File file) throws Exception { /** * Uses the predefined data source for creating the OBDAModel. */ OBDADataSource dataSource = obdaModelController.getSources().get(0); OntopMappingSQLAllConfiguration configuration = OntopMappingSQLAllConfiguration.defaultBuilder() .properties(DataSource2PropertiesConvertor.convert(dataSource)) .r2rmlMappingFile(file) .build(); SQLPPMapping parsedModel = configuration.loadProvidedPPMapping(); try{ /** * TODO: improve this inefficient method (batch processing, not one by one) */ for (SQLPPTriplesMap mapping : parsedModel.getTripleMaps()) { if (mapping.getTargetAtoms().toString().contains("BNODE")) { JOptionPane.showMessageDialog(getWorkspace(), "The mapping " + mapping.getId() + " contains BNode. -ontoPro- does not support it yet."); } else { obdaModelController.addTriplesMap(mapping, false); } } } catch (DuplicateMappingException dm) { JOptionPane.showMessageDialog(getWorkspace(), "Duplicate mapping id found. Please correct the Resource node name: " + dm.getLocalizedMessage()); throw new RuntimeException("Duplicate mapping found: " + dm.getMessage()); } }
@Override public boolean match(SQLPPTriplesMap object) { final OBDASQLQuery bodyquery = (OBDASQLQuery) object.getSourceQuery(); boolean isMatch = false; for (String keyword : vecKeyword) { isMatch = match(keyword.trim(), bodyquery.toString()); if (isMatch) { break; // end loop if a match is found! } } // no match found! return (bNegation ? !isMatch : isMatch); }
private ImmutableList<TargetAtom> getNewTargetAtoms(SQLPPTriplesMap formerTriplesMap, IRI removedPredicateIRI, AtomicInteger counter) { return formerTriplesMap.getTargetAtoms().stream() .filter(a -> { if (a.getPredicateIRI() .filter(i -> i.equals(removedPredicateIRI)) .isPresent()) { counter.incrementAndGet(); return false; } return true; }) .collect(ImmutableCollectors.toList()); }
@Override public String getProvenanceInfo() { String info = "id: " + triplesMap.getId(); info += "\ntarget atom: " + targetAtom.toString(); info += "\nsource query: " + triplesMap.getSourceQuery(); return info; }
OBDASQLQuery sourceQuery = mappingAxiom.getSourceQuery(); for (TargetAtom atom : mappingAxiom.getTargetAtoms()) { PPMappingAssertionProvenance provenance = mappingAxiom.getMappingAssertionProvenance(atom); try { errorMessages.add("Error: " + e.getMessage() + " \nProblem location: source query of triplesMap \n[" + mappingAxiom.getTriplesMapProvenance().getProvenanceInfo() + "]");
public int indexOf(URI currentSource, String mappingId) { ImmutableList<SQLPPTriplesMap> sourceMappings = ImmutableList.copyOf(triplesMapMap.values()); if (sourceMappings == null) { return -1; } for(int i=0; i < sourceMappings.size(); i++) { if (sourceMappings.get(i).getId().equals(mappingId)) return i; } return -1; }
private void menuExecuteBodyActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_menuExecuteBodyActionPerformed SQLPPTriplesMap mapping = mappingList.getSelectedValue(); if (mapping == null) { return; } final String sqlQuery = mapping.getSourceQuery().toString(); SQLQueryPanel pnlQueryResult = new SQLQueryPanel(selectedSource, sqlQuery); JDialog dlgQueryResult = new JDialog(); DialogUtils.installEscapeCloseOperation(dlgQueryResult); dlgQueryResult.setContentPane(pnlQueryResult); dlgQueryResult.pack(); dlgQueryResult.setLocationRelativeTo(this); dlgQueryResult.setVisible(true); dlgQueryResult.setTitle("SQL Query Result"); }// GEN-LAST:event_menuExecuteBodyActionPerformed
@Override public boolean match(SQLPPTriplesMap object) { boolean isMatch = false; for (String keyword : vecKeyword) { // Check in the Mapping ID final String mappingId = object.getId(); isMatch = MappingIDTreeModelFilter.match(keyword.trim(), mappingId); if (isMatch) { break; // end loop if a match is found! } // Check in the Mapping Target Query for (TargetAtom targetAtom : object.getTargetAtoms()) { isMatch = isMatch || TreeModelTools.match(keyword.trim(), targetAtom); } if (isMatch) { break; // end loop if a match is found! } // Check in the Mapping Source Query final OBDASQLQuery query = object.getSourceQuery(); isMatch = MappingSQLStringTreeModelFilter.match(keyword.trim(), query.toString()); if (isMatch) { break; // end loop if a match is found! } } // no match found! return bNegation != isMatch; } }
public void updateMappingsSourceQuery(String triplesMapId, OBDASQLQuery sourceQuery) { SQLPPTriplesMap formerTriplesMap = getTriplesMap(triplesMapId); if (formerTriplesMap != null) { SQLPPTriplesMap newTriplesMap = new OntopNativeSQLPPTriplesMap(triplesMapId, sourceQuery, formerTriplesMap.getTargetAtoms()); triplesMapMap.put(triplesMapId, newTriplesMap); fireMappingUpdated(); } }
private SQLPPTriplesMap updateMapping(SQLPPTriplesMap formerTriplesMap, IRI removedPredicateIRI, AtomicInteger counter) { int initialCount = counter.get(); ImmutableList<TargetAtom> newTargetAtoms = getNewTargetAtoms(formerTriplesMap, removedPredicateIRI, counter); if (counter.get() > initialCount) { if (newTargetAtoms.isEmpty()) { throw new IllegalStateException("Mapping should be deleted"); } else { SQLPPTriplesMap newTriplesMap = new OntopNativeSQLPPTriplesMap(formerTriplesMap.getId(), formerTriplesMap.getSourceQuery(), newTargetAtoms); return newTriplesMap; } } else return formerTriplesMap; }
private static ImmutableMap<String, SQLPPTriplesMap> indexMappingsById(ImmutableList<SQLPPTriplesMap> mappings) throws IllegalArgumentException { Map<String, SQLPPTriplesMap> mappingIndexById = new HashMap<>(); for (SQLPPTriplesMap axiom : mappings) { String id = axiom.getId(); if (mappingIndexById.containsKey(id)) { // Should have already been detected by checkDuplicates. throw new IllegalArgumentException(String.format("Not unique mapping ID found : %s", id)); } mappingIndexById.put(id, axiom); } return ImmutableMap.copyOf(mappingIndexById); }
public void updateTargetQueryMapping(String id, ImmutableList<TargetAtom> targetQuery) { SQLPPTriplesMap formerTriplesMap = getTriplesMap(id); if (formerTriplesMap != null) { SQLPPTriplesMap newTriplesMap = new OntopNativeSQLPPTriplesMap(id, formerTriplesMap.getSourceQuery(), targetQuery); triplesMapMap.put(id, newTriplesMap); fireMappingUpdated(); } }
private void writeMappingDeclaration(BufferedWriter writer) throws IOException { writer.write(OntopNativeMappingParser.MAPPING_DECLARATION_TAG + " " + OntopNativeMappingParser.START_COLLECTION_SYMBOL); writer.write("\n"); boolean needLineBreak = false; for (SQLPPTriplesMap axiom : ppMapping.getTripleMaps()) { if (needLineBreak) { writer.write("\n"); } writer.write(OntopNativeMappingParser.Label.mappingId.name() + "\t" + axiom.getId() + "\n"); ImmutableList<TargetAtom> targetQuery = axiom.getTargetAtoms(); writer.write(OntopNativeMappingParser.Label.target.name() + "\t\t" + printTargetQuery(targetQuery) + "\n"); OBDASQLQuery sourceQuery = axiom.getSourceQuery(); writer.write(OntopNativeMappingParser.Label.source.name() + "\t\t" + printSourceQuery(sourceQuery) + "\n"); needLineBreak = true; } writer.write(OntopNativeMappingParser.END_COLLECTION_SYMBOL); writer.write("\n\n"); }