Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package it.unibz.krdb.obda.owlapi3.directmapping;
  
  /*
   * #%L
   * ontop-obdalib-owlapi3
   * %%
   * Copyright (C) 2009 - 2014 Free University of Bozen-Bolzano
   * %%
   * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
  */
 
 
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 //import com.hp.hpl.jena.iri.impl.IRIFactoryImpl;
 //import it.unibz.krdb.obda.model.net.IRIFactory;
 


A class that provides manipulation for Direct Mapping

Author(s):
Victor
 
 
 
 public class DirectMappingEngine {
 	
 	private JDBCConnectionManager conMan = null;
 	private DBMetadata metadata = null;
 	private String baseuri;
 	private int mapidx = 1;
 	
 	public DirectMappingEngine(String baseUriint mapnr){
 		 = JDBCConnectionManager.getJDBCConnectionManager();
 		 = baseUri;
 		 = mapnr + 1;
 	}
 	
 	public DirectMappingEngine(DBMetadata metadataString baseUriint mapnr){
 		this. = metadata;
 		 = baseUri;
 		 = mapnr + 1;
 	}
 	
 	
 	/*
 	 * set the base URI used in the ontology
 	 */
 	public void setBaseURI(String prefix){
 		if(prefix.endsWith("#")){
 			this. = prefix.replace("#""/");
 		}else if(prefix.endsWith("/")){
			this. = prefix;
		}else this. = prefix+"/";
	}



enrich the ontology according to the datasources specified in the OBDAModel basically from the database structure

Parameters:
ontology
model
Returns:
null the ontology is updated
Throws:
Exceptions
	public void enrichOntology(OWLOntology ontologyOBDAModel modelthrows OWLOntologyStorageExceptionSQLException{
		List<OBDADataSourcesourcelist = new ArrayList<OBDADataSource>();
		sourcelist = model.getSources();
		}else{
		}
		//For each data source, enrich into the ontology
		if ( == null) {
			for (int i = 0; i < sourcelist.size(); i++) {
						ontology);
			}
else
			oe.enrichOntology(this.ontology);
	}



enrich the ontology according to mappings used in the model

Parameters:
manager
model
Returns:
a new ontology storing all classes and properties used in the mappings
Throws:
Exceptions
		OWLDataFactory dataFactory = manager.getOWLDataFactory();
		Set<Predicateclassset = model.getDeclaredClasses();
		Set<Predicateobjectset = model.getDeclaredObjectProperties();
		//Add all the classes
		for(Iterator<Predicateit = classset.iterator(); it.hasNext();){
			OWLClass newclass = dataFactory.getOWLClass(IRI.create(it.next().getName().toString()));
			OWLDeclarationAxiom declarationAxiom = dataFactory.getOWLDeclarationAxiom(newclass);
			manager.addAxiom(ontology,declarationAxiom );
		}
		//Add all the object properties
		for(Iterator<Predicateit = objectset.iterator(); it.hasNext();){
			OWLObjectProperty newclass = dataFactory.getOWLObjectProperty(IRI.create(it.next().getName().toString()));
			OWLDeclarationAxiom declarationAxiom = dataFactory.getOWLDeclarationAxiom(newclass);
			manager.addAxiom(ontology,declarationAxiom );
		}
		//Add all the data properties
		for(Iterator<Predicateit = dataset.iterator(); it.hasNext();){
			OWLDataProperty newclass = dataFactory.getOWLDataProperty(IRI.create(it.next().getName().toString()));
			OWLDeclarationAxiom declarationAxiom = dataFactory.getOWLDeclarationAxiom(newclass);
			manager.addAxiom(ontology,declarationAxiom );
		}
		return ontology;		
	}


extract all the mappings from a datasource

Parameters:
source
Returns:
a new OBDA Model containing all the extracted mappings
Throws:
java.lang.Exception
		OBDAModelImpl model = new OBDAModelImpl();
		return extractMappings(modelsource);
	}
	public OBDAModel extractMappings(OBDAModel modelOBDADataSource sourcethrows Exception{
		insertMapping(sourcemodel);
		return model;
	}


extract mappings from given datasource, and insert them into the given model

Parameters:
source
model
Returns:
null Duplicate Exception may happen, since mapping id is generated randomly and same id may occur
Throws:
java.lang.Exception
		model.addSource(source);
	}
	public void insertMapping(DBMetadata metadataOBDAModel modelURI sourceUrithrows SQLExceptionDuplicateMappingException{			
		if ( == null || .isEmpty())
		List<TableDefinitiontables = metadata.getTableList();
		List<OBDAMappingAxiommappingAxioms = new ArrayList<OBDAMappingAxiom>();
		for (int i = 0; i < tables.size(); i++) {
			TableDefinition td = tables.get(i);
			model.addMappings(sourceUrigetMapping(tdmetadata));
		}
		model.addMappings(sourceUrimappingAxioms);
		for (URI uri : model.getMappings().keySet()) {
			for (OBDAMappingAxiom mapping : model.getMappings().get(uri)) {
				OBDAQuery q = mapping.getTargetQuery();
				CQIE rule = (CQIEq;
				for (Function f : rule.getBody()) {
					if (f.getArity() == 1)
					else if (f.getFunctionSymbol().getType(1)
					else
				}
			}
		}
	}

generate a mapping axiom from a table of some database

Parameters:
table : the datadefinition from which mappings are extraced
source : datasource that the table may refer to, such as foreign keys
Returns:
a List of OBDAMappingAxiom-s
Throws:
java.lang.Exception
		return getMapping(table,.getMetaData(source),);
	}


generate a mapping axiom from a table of a database

Parameters:
table : the datadefinition from which mappings are extraced
metadata : the metadata of the database required
baseUri : the base uri needed for direct mapping axiom
Returns:
a List of OBDAMappingAxiom-s
	public List<OBDAMappingAxiomgetMapping(DataDefinition tableDBMetadata metadataString baseUri) {
		OBDADataFactory dfac = OBDADataFactoryImpl.getInstance();
		try {
			dma = new DirectMappingAxiom(baseUritablemetadatadfac);
catch (Exception e) {
		}
		dma.setbaseuri(baseUri);
		axioms.add(dfac.getRDBMSMappingAxiom("MAPPING-ID"+,dma.getSQL(), dma.getCQ()));
		Map<StringCQIErefAxioms = dma.getRefAxioms();
		for (String refSQL : refAxioms.keySet()) {
			axioms.add(dfac.getRDBMSMappingAxiom("MAPPING-ID"+refSQLrefAxioms.get(refSQL)));
		}
		return axioms;
	}
New to GrepCode? Check out our FAQ X