/** * the method that gives the obda model based on the given graph * @param dataSource - the datasource of the model * @return the read obda model */ public OBDAModel readModel(OBDADataSource dataSource){ try { obdaModel.addSource(dataSource); URI sourceUri = dataSource.getSourceID(); //add to the model the mappings retrieved from the manager obdaModel.addMappings(sourceUri, manager.getMappings(m)); } catch (DuplicateMappingException e) { e.printStackTrace(); } return obdaModel; }
/** * The save/write operation. * * @param file * The target file object to which the model is saved. * @throws IOException */ public void save(File file) throws IOException { try { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writePrefixDeclaration(writer); for (OBDADataSource source : model.getSources()) { writeSourceDeclaration(source, writer); writeMappingDeclaration(source, writer); } writer.flush(); writer.close(); } catch (IOException e) { throw new IOException(String.format("Error while saving the OBDA model to file located at %s.\n" + "Make sure you have the write permission at the location specified.", file.getAbsolutePath())); } }
public R2RMLWriter(OBDAModel obdamodel, URI sourceURI, OWLOntology ontology) { this.sourceUri = sourceURI; this.mappings = obdamodel.getMappings(sourceUri); this.prefixmng = obdamodel.getPrefixManager(); this.ontology = ontology; }
/** * Create an IO manager for saving/loading the OBDA model. * * @param model * The target OBDA model. */ public ModelIOManager(OBDAModel model) { this.model = model; prefixManager = model.getPrefixManager(); dataFactory = model.getDataFactory(); // Register available parsers for target query register(new TurtleOBDASyntaxParser(prefixManager)); }
if (obdaModel.getSources().size() == 0) obdaModel.addSource(getMemOBDADataSource("MemH2")); obdaModel.getOntologyVocabulary().merge(tbox.getVocabulary());
public void refresh() { final List<OBDADataSource> sourceList = model.getSources(); for (OBDADataSource database : sourceList) { URI sourceUri = database.getSourceID(); List<OBDAMappingAxiom> mappingList = model.getMappings(sourceUri); HashMap<String, Integer> mappingStat = new HashMap<String, Integer>(); for (OBDAMappingAxiom mapping : mappingList) { String mappingId = mapping.getId(); int triplesCount = 0; try { OBDASQLQuery sourceQuery = mapping.getSourceQuery(); int tuples = getTuplesCount(database, sourceQuery); List<Function> targetQuery = mapping.getTargetQuery(); int atoms = targetQuery.size(); triplesCount = tuples * atoms; } catch (Exception e) { triplesCount = -1; // fails to count log.error(e.getMessage()); } mappingStat.put(mappingId, triplesCount); } String sourceId = sourceUri.toString(); statistics.put(sourceId, mappingStat); } }
obdaModel.addSource(source); obdaModel.getOntologyVocabulary().merge(ontology.getVocabulary());
@Override public Object clone() { OBDAModel clone = dfac.getOBDAModel(); for (OBDADataSource source : datasources.values()) { clone.addSource((OBDADataSource) source.clone()); for (ArrayList<OBDAMappingAxiom> mappingList : mappings.values()) { for (OBDAMappingAxiom mapping : mappingList) { try { clone.addMapping(source.getSourceID(), (OBDAMappingAxiom) mapping.clone(), false); } catch (DuplicateMappingException e) { // Does nothing } } } } return clone; }
sourceUri = URI.create(inputParamter); datasource = model.getDataFactory().getDataSource(sourceUri); } else if (parameter.equals(Label.connectionUrl.name())) { datasource.setParameter(RDBMSourceParameterConstants.DATABASE_URL, inputParamter); model.addSource(datasource); return sourceUri;
private void readPrefixDeclaration(BufferedReader reader) throws IOException { final PrefixManager pm = model.getPrefixManager(); String line = ""; while (!(line = reader.readLine()).isEmpty()) { String[] tokens = line.split("[\t| ]+"); pm.addPrefix(tokens[0], tokens[1]); } }
obdaModelForMaterialization.getOntologyVocabulary().merge(tbox.getVocabulary());
private void writeMappingDeclaration(OBDADataSource source, BufferedWriter writer) throws IOException { final URI sourceUri = source.getSourceID(); writer.write(MAPPING_DECLARATION_TAG + " " + START_COLLECTION_SYMBOL); writer.write("\n"); boolean needLineBreak = false; for (OBDAMappingAxiom mapping : model.getMappings(sourceUri)) { if (needLineBreak) { writer.write("\n"); } writer.write(Label.mappingId.name() + "\t" + mapping.getId() + "\n"); List<Function> targetQuery = mapping.getTargetQuery(); writer.write(Label.target.name() + "\t\t" + printTargetQuery(targetQuery) + "\n"); OBDASQLQuery sourceQuery = mapping.getSourceQuery(); writer.write(Label.source.name() + "\t\t" + printSourceQuery(sourceQuery) + "\n"); needLineBreak = true; } writer.write(END_COLLECTION_SYMBOL); writer.write("\n\n"); }
private void saveMapping(URI dataSourceUri, String mappingId, String sourceQuery, List<Function> targetQuery) { try { OBDAMappingAxiom mapping = dataFactory.getRDBMSMappingAxiom(mappingId, dataFactory.getSQLQuery(sourceQuery), targetQuery); model.addMapping(dataSourceUri, mapping, false); } catch (DuplicateMappingException e) { // NO-OP: Ignore it as duplicates won't be loaded to the model } }
/** * the method that gives the obda model based on the given graph * @param sourceUri - the uri of the datasource of the model * @return the read obda model */ public OBDAModel readModel(URI sourceUri){ try { //add to the model the mappings retrieved from the manager obdaModel.addMappings(sourceUri, manager.getMappings(m)); } catch (DuplicateMappingException e) { e.printStackTrace(); } return obdaModel; }
/** * Initialization code which is called from both of the two constructors. * @param obdaModel * */ private void init(OWLOntology rootOntology, OBDAModel obdaModel, OWLReasonerConfiguration configuration, Properties preferences){ pm = configuration.getProgressMonitor(); man = rootOntology.getOWLOntologyManager(); if (obdaModel != null) this.obdaModel = (OBDAModel)obdaModel.clone(); this.preferences.putAll(preferences); extractVersion(); prepareReasoner(); }
private void writePrefixDeclaration(BufferedWriter writer) throws IOException { final Map<String, String> prefixMap = model.getPrefixManager().getPrefixMap(); if (prefixMap.size() == 0) { return; // do nothing if there is no prefixes to write } writer.write(PREFIX_DECLARATION_TAG); writer.write("\n"); for (String prefix : prefixMap.keySet()) { String uri = prefixMap.get(prefix); writer.write(prefix + (prefix.length() >= 9 ? "\t" : "\t\t") + uri + "\n"); } writer.write("\n"); }
obdaModelForMaterialization.getOntologyVocabulary().merge(translatedOntologyMerge.getVocabulary());
e.printStackTrace(); URI srcURI = model.getSources().get(0).getSourceID();