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 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 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); }
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); }
@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) { boolean isMatch = false; for (String keyword : vecKeyword) { isMatch = match(keyword.trim(), object.getId()); if (isMatch) { break; // end loop if a match is found! } } // no match found! return (bNegation ? !isMatch : isMatch); }
@Override public String getProvenanceInfo() { String info = "id: " + triplesMap.getId(); info += "\ntarget atom: " + targetAtom.toString(); info += "\nsource query: " + triplesMap.getSourceQuery(); return info; }
@Deprecated public void addTriplesMap(URI sourceID, SQLPPTriplesMap triplesMap, boolean disableFiringMappingInsertedEvent) throws DuplicateMappingException { String mapId = triplesMap.getId(); if (triplesMapMap.containsKey(mapId)) throw new DuplicateMappingException("ID " + mapId); triplesMapMap.put(mapId, triplesMap); if (!disableFiringMappingInsertedEvent) fireMappingInserted(sourceID); }
public void addTriplesMap(SQLPPTriplesMap triplesMap, boolean disableFiringMappingInsertedEvent) throws DuplicateMappingException { String mapId = triplesMap.getId(); if (triplesMapMap.containsKey(mapId)) throw new DuplicateMappingException("ID " + mapId); triplesMapMap.put(mapId, triplesMap); if (!disableFiringMappingInsertedEvent) fireMappingInserted(source.getSourceID()); }
duplicateIds.add(mapping.getId()); if (--remaining == 0) break;
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 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); }
tables.add(table); } catch (Exception e) { errorMessage.add("Error in mapping with id: " + axiom.getId() + " \n Description: " + ((e.getMessage()!= null) ? e.getMessage() : e.getCause()) + " \nMapping: [" + axiom.toString() + "]");
/*** * 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); } }
tables.add(table); } catch (Exception e) { errorMessage.add("Error in mapping with id: " + axiom.getId() + " \n Description: " + ((e.getMessage()!= null) ? e.getMessage() : e.getCause()) + " \nMapping: [" + axiom.toString() + "]");
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"); }
public void refresh() { OBDADataSource source = obdaModel.getDatasource(); List<SQLPPTriplesMap> mappingList = obdaModel.generatePPMapping().getTripleMaps(); HashMap<String, Integer> mappingStat = new HashMap<String, Integer>(); for (SQLPPTriplesMap mapping : mappingList) { String mappingId = mapping.getId(); int triplesCount = 0; try { OBDASQLQuery sourceQuery = mapping.getSourceQuery(); int tuples = getTuplesCount(sourceQuery, source); ImmutableList<TargetAtom> targetQuery = mapping.getTargetAtoms(); int atoms = targetQuery.size(); triplesCount = tuples * atoms; } catch (Exception e) { triplesCount = -1; // fails to count log.error(e.getMessage()); } mappingStat.put(mappingId, triplesCount); } statistics.put(source.getSourceID().toString(), mappingStat); }
@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; } }
private void removeMapping() { int[] indexes = mappingList.getSelectedIndices(); if (indexes == null) { return; } int confirm = JOptionPane.showConfirmDialog( this, "Proceed deleting " + indexes.length + " mappings?", "Conform", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.CANCEL_OPTION || confirm == JOptionPane.CLOSED_OPTION) { return; } // The manager panel can handle multiple deletions. Object[] values = mappingList.getSelectedValues(); OBDAModel controller = apic; URI srcuri = selectedSource.getSourceID(); for (int i = 0; i < values.length; i++) { SQLPPTriplesMap mapping = (SQLPPTriplesMap) values[i]; if (mapping!=null) controller.removeTriplesMap(srcuri, mapping.getId()); } mappingList.clearSelection(); }
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()); } }