📄 c_normalisationimpl.java
字号:
*/
private void traverseAndProcessElements (XSDNode[] elms) throws Exception{ // not used, too costly procedure
int length=elms.length;
for (int i = 0; i < length; i++) {
XSDElement elm = (XSDElement)elms[i];
ElementUse elmUse = new ElementUse(elm, this, null);
elmUse.createNormMapEntries();
elmUse.traverseAndProcessEventualNestedElementUses();
}
}
private void traverseAndProcessElements (XSDNode[] elms, String rootElement) throws NormalisationException {
try {
int length=elms.length;
for (int i = 0; i < length; i++) {
XSDElement elm = (XSDElement)elms[i];
if (rootElement.equals(elm.getName())) {
ElementUse elmUse = new ElementUse(elm, this, null);
elmUse.createNormMapEntries();
elmUse.traverseAndProcessEventualNestedElementUses();
return;
}
}
throw new NormalisationException("Specified root element not found in the associated XML Schema");
} catch (Exception e) {
e.printStackTrace();
throw new NormalisationException("Exception while defining Normalisation Map", e);
}
}
/*
----------------------------------- procedures supporting conceptual model extraction --------------------------------------------
*/
public void addConceptToTargetModel (int xsdComponentHashCode, String newConceptLabel) throws Exception {
try {
List changes=new LinkedList();
String newConceptURI = m_oimodelTargetOntology.getURI(newConceptLabel);
Concept newConcept = m_oimodelTargetOntology.getConcept(newConceptURI);
changes.add(new AddEntity(newConcept));
changes.add(new AddSubConcept(m_KAON_RootConcept, newConcept)); // maybe make this optional
m_oimodelTargetOntology.applyChanges(changes);
Vector createdURIs = new Vector();
createdURIs.add(newConceptURI);
m_normalisationTable.put(new Integer(xsdComponentHashCode), createdURIs);
} catch (KAONException e) { // this is just a workaround solution for repeated names in local elm declarations ... find other solution!!!
addConceptToTargetModel (xsdComponentHashCode, newConceptLabel + "_");
}
}
public void addPropertyToTargetModel (int xsdComponentHashCode, String newPropertyLabel) throws Exception {
try {
List changes=new LinkedList();
String newPropertyURI = m_oimodelTargetOntology.getURI(newPropertyLabel);
Property newProperty = m_oimodelTargetOntology.getProperty(newPropertyURI);
changes.add(new AddEntity(newProperty));
//System.out.println(newPropertyURI+ "...."+xsdComponentHashCode);
m_oimodelTargetOntology.applyChanges(changes);
Vector createdURIs = new Vector();
createdURIs.add(newPropertyURI);
m_normalisationTable.put(new Integer(xsdComponentHashCode), createdURIs);
} catch (KAONException e) { // this is just a workaround solution for repeated names in local elm declarations ... find other solution!!!
addPropertyToTargetModel (xsdComponentHashCode, newPropertyLabel + "_");
}
}
public void addSubtreeToTargetModel (int xsdComponentHashCode, String labelBase) throws Exception {
try {
List changes=new LinkedList();
String newConceptURI = m_oimodelTargetOntology.getURI(labelBase + "_class");
Concept newConcept = m_oimodelTargetOntology.getConcept(newConceptURI);
String newPropertyURI = m_oimodelTargetOntology.getURI(labelBase + "_value");
Property newProperty = m_oimodelTargetOntology.getProperty(newPropertyURI);
changes.add(new AddEntity(newConcept));
changes.add(new AddSubConcept(m_KAON_RootConcept, newConcept)); // maybe make this optional
changes.add(new AddEntity(newProperty));
changes.add(new AddPropertyRange(newProperty, m_oimodelTargetOntology.getConcept(CNOVocabulary.URI_RDFS_LITERAL)));
changes.add(new AddPropertyDomain(newProperty, newConcept));
m_oimodelTargetOntology.applyChanges(changes);
Vector createdURIs = new Vector();
createdURIs.add(newConceptURI);
createdURIs.add(newPropertyURI);
createdURIs.add(CNOVocabulary.URI_RDFS_LITERAL);
m_normalisationTable.put(new Integer(xsdComponentHashCode), createdURIs);
} catch (KAONException e) { // this is just a workaround solution for repeated names in local elm declarations ... find other solution!!!
addSubtreeToTargetModel (xsdComponentHashCode, labelBase + "_");
}
}
public void addPropertyRangeToTargetModel (int xsdComponentHashCode, String rangeEntityURI) throws Exception {
List changes=new LinkedList();
String propertyURI = getNormalizedEntityFirstURI(xsdComponentHashCode);
// String propertyURI = (String) m_normalisationTable.get(new Integer(xsdComponentHashCode));
Property property = m_oimodelTargetOntology.getProperty(propertyURI);
Concept rangeConcept = m_oimodelTargetOntology.getConcept(rangeEntityURI);
changes.add(new AddPropertyRange(property, rangeConcept));
m_oimodelTargetOntology.applyChanges(changes);
}
public void addPropertyDomainToTargetModel (int xsdComponentHashCode, String domainEntityURI) throws Exception {
List changes=new LinkedList();
String propertyURI = getNormalizedEntityFirstURI(xsdComponentHashCode);
// String propertyURI = (String) m_normalisationTable.get(new Integer(xsdComponentHashCode));
Property property = m_oimodelTargetOntology.getProperty(propertyURI);
Concept domainConcept = m_oimodelTargetOntology.getConcept(domainEntityURI);
changes.add(new AddPropertyDomain(property, domainConcept));
m_oimodelTargetOntology.applyChanges(changes);
}
/*
----------------------------------- procedures supporting norm map definition --------------------------------------------
*/
public String addNodeBridgeToNormMap (String xmlEntityXPath, String targetEntityURI) throws Exception {
String newNBURI = m_normmap.createNewURIForNormMapInstance();
m_normmap.addNewNodeBridge(newNBURI);
NodeBridge newNB = m_normmap.getNodeBridge(newNBURI);
newNB.setRelatedXPathEntity(xmlEntityXPath);
newNB.setRelatedOntologyEntity(targetEntityURI);
return newNBURI;
}
public String addPropertyNodeToNormMap (String subjectEntityURI, String predicateEntityURI, String objectEntityURI) throws Exception {
PropertyNode newPN = new PropertyNode(m_normmap, subjectEntityURI, predicateEntityURI, objectEntityURI);
m_normmap.addPropertyNode(newPN);
return newPN.getURI();
}
public String addPathBridgeToNormMap (String relatedXPath, String relatedOPathURI) throws Exception {
String newPBURI = m_normmap.createNewURIForNormMapInstance();
m_normmap.addNewPathBridge(newPBURI);
PathBridge newPB = m_normmap.getPathBridge(newPBURI);
newPB.setRelatedXPath(relatedXPath);
newPB.setRelatedOPath(relatedOPathURI);
return newPBURI;
}
public void addHasBridgeToNodeBridge (String nodeBridgeURI, String hasBridgeURI) throws Exception {
NodeBridge nB = m_normmap.getNodeBridge(nodeBridgeURI);
nB.addHasBridge(hasBridgeURI);
}
public void addContextPropertyNodeToNodeBridge (String nodeBridgeURI, String propertyNodeURI) throws Exception {
NodeBridge nB = m_normmap.getNodeBridge(nodeBridgeURI);
nB.setInContextOf(propertyNodeURI);
}
/*
----------------------------------- more supporting procedures --------------------------------------------
*/
public Vector getNormalizedEntityURIs ( int xsdComponentHashCode ) throws Exception{
return (Vector) m_normalisationTable.get(new Integer(xsdComponentHashCode));
}
public void addEntryToCNormTable(int nodeHashCode, Vector extractedEntityURIs) throws Exception {
m_normalisationTable.put(new Integer(nodeHashCode), extractedEntityURIs);
}
public String getNormalizedEntityFirstURI ( int xsdComponentHashCode ) throws Exception{
Vector normalizedURIs = (Vector) m_normalisationTable.get(new Integer(xsdComponentHashCode));
return (String) (normalizedURIs.toArray())[0];
}
/*
public String getNormalizedEntityURI ( int xsdComponentHashCode ) throws Exception{
return (String) m_normalisationTable.get(new Integer(xsdComponentHashCode));
}
public void addEntryToCNormTable(int nodeHashCode, String extractedEntityURI) throws Exception {
m_normalisationTable.put(new Integer(nodeHashCode), extractedEntityURI);
}
*/
public boolean isAllreadyNormalized(int hashCode) throws Exception {
return m_normalisationTable.containsKey(new Integer(hashCode));
}
/*
----------------------------------- save functions --------------------------------------------
*/
/**
* Saves the extracted conceptual model to the default location associated at constructor.
*/
public void saveNormalizedModel() throws NormalisationException {
saveNormalizedModel( m_strTargetOntologyPhysicalURI );
}
/**
* Saves the extracted conceptual model to the defined location.
* @param strPhysicalURI physical location for the conceptual mode RDFS file
*/
public void saveNormalizedModel(String strPhysicalURI) throws NormalisationException {
try {
// if no filename has been specified, use the default
if(strPhysicalURI==null)
strPhysicalURI = m_strTargetOntologyPhysicalURI;
TransformationUtil.saveOIModel( m_oimodelTargetOntology, strPhysicalURI );
} catch (Exception e) {
throw new NormalisationException("Exception while saving extracted ontology", e);
}
}
/**
* Saves the produced Normalisation Map to the default location associated at constructor.
*/
public void saveNormMap() throws NormalisationException {
saveNormMap( m_strNormMapPhysicalURI );
}
/**
* Saves the produced Normalisation Map to the defined location.
* @param strPhysicalURI physical location for the Normalisation Map file
*/
public void saveNormMap(String strPhysicalURI) throws NormalisationException {
try {
m_normmap.saveNormMap();
} catch (Exception e) {
throw new NormalisationException("Exception while saving Normalisation Map", e);
}
}
/*
----------------------------------- getters & setters --------------------------------------------
*/
/**
* Returns the produced Normalisation Map.
*/
public OIModel getNormMap() {
return m_normmap.getNormMapInstance();
}
/**
* Returns the produced RDFS conceptual model (ontology).
*/
public OIModel getNormalizedModel() {
return m_oimodelTargetOntology;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -