⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 normmap.java

📁 normkit is a set of tools supporting ontology learning. from xml,xsd to rdfs.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package it.itc.ectrl.normkit.common.NormMapModel;

import java.util.*;

import edu.unika.aifb.kaon.api.KAONException;
import edu.unika.aifb.kaon.api.change.AddIncludedOIModel;
import edu.unika.aifb.kaon.api.oimodel.OIModel;
import edu.unika.aifb.kaon.api.oimodel.Instance;

import edu.unika.aifb.kaon.apionrdf.OIModelImpl;
import edu.unika.aifb.kaon.apionrdf.InstanceImpl;
import edu.unika.aifb.kaon.apionrdf.KAONConnectionImpl;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.Attr;
import org.xml.sax.InputSource;

import it.itc.ectrl.normkit.common.*;

import oracle.xml.parser.schema.*;

import javax.xml.transform.TransformerFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;


/**
 * Class representing a Normalisation Map as an instance of the Conceptual Normalisation Ontology (CNO).
 * @author Oliver Fodor (fodor@itc.it)
 */
public class NormMap extends CNOEntity {
    /**
     * Physical location of the NormMap instance.
     */
    String m_strNormMapPhysicalURI;

    /**
     * Physical location of the normalisation ontology.
     */
    String m_strCNOPhysicalURI = NormMap.class.getResource("res/normbridges.xml").toString();

    /**
     * Logical URI of the NormMap instance.
     */
    String m_strURINormMap;

    /**
     * Logical URI of the related conceptual model.
     */
    String m_strURIOntology;

    /**
     * Logical URI of the related XML Schema document.
     */
    String m_strURIXSDocument;

    /**
     * Model for the Normalisation Ontology.
     */
    OIModel m_oimodelCNO;

           // the normalisation ontology
    /**
     * Model for the NormMap instance.
     */
    OIModel m_oimodelCNOInstance;

   // the instance of the norm. ontology = the actual norm map
    /**
     * Model encompassing the map ontology and instance.
     */
    OIModel m_oimodelNormMap;       // the container for the two models above


    /**
     * KAON connection for the map model.
     */
    KAONConnectionImpl m_KAONConnection;

    /**
     * Set of node bridges within this map as <URI, bridge> pairs.
     */
    Map m_mapNodeBridges = new HashMap();

    /**
     * Set of path bridges within this map as <URI, bridge> pairs.
     */
    Map m_mapPathBridges = new HashMap();

    /**
     * Set of property nodes within this map as <URI, node> pairs.
     */
    Map m_mapPropertyNodes = new HashMap();

    /**
     * Creates an instance of this class and sets its parameters.
     * @param strURILogical logical URI of the Normalisation Map to be created
     * @param strURIPhysical physical location for the Normalisation Map file to be created
     * @param strURIRelatedXSD URI of the XML Schema which this map refers to
     * @param strURIRelatedOntology URI of the RDFS conceptual model which this map refers to
     */
    public NormMap(String strURILogical, String strURIPhysical, String strURIRelatedXSD, String strURIRelatedOntology) throws NormalisationException {

        m_strNormMapPhysicalURI = strURIPhysical;

        m_strURINormMap = strURILogical;
        m_strURIXSDocument = strURIRelatedXSD;
        m_strURIOntology = strURIRelatedOntology;

        initialize();
    }

    /**
     * Creates an instance of this class from a NormMap file.
     * @param normMapPath Physical URI of the Normalisation Map to be read-in
     */
    public NormMap(String normMapPath) throws NormalisationException {

        m_strNormMapPhysicalURI = normMapPath;

        initialize();

        parse();

    }

    private void initialize() throws NormalisationException {

        try {

            m_KAONConnection = new KAONConnectionImpl();

            m_oimodelNormMap = m_KAONConnection.createOIModel("file:tempNormMap", "normMap");

        } catch (KAONException e) {

            throw new NormalisationException("KAON Exception while creating connection.", e);

        }

    }

    /**
     * Reads in models (XML Schema and RDFS) related by this map and creates a corresponding map entity.
     */
    public void readModels() throws Exception
    {
        readNormMapModels( false );

        createNormMapElement();
    }

    private void readNormMapModels(boolean bOpening) throws Exception
    {

        if( bOpening )
        {
            //testURIValidity( m_strNormMapPhysicalURI, "NormMap" );
            m_oimodelCNOInstance = m_KAONConnection.openOIModelPhysical( m_strNormMapPhysicalURI );
            // set the Mapping logical URI
            m_strURINormMap = m_oimodelCNOInstance.getLogicalURI();
        }
        else
        {
            if( m_strNormMapPhysicalURI != null )
                { //testURIValidity( m_strNormMapPhysicalURI, "NormMap" );
                }
            else
                m_strNormMapPhysicalURI = "file:tempNormMap";

            m_oimodelCNOInstance = m_KAONConnection.createOIModel(m_strNormMapPhysicalURI, m_strURINormMap);
        }

        m_oimodelCNO = m_KAONConnection.openOIModelPhysical( m_strCNOPhysicalURI );

        // mapping
            List listChanges = new LinkedList();

            listChanges.add( new AddIncludedOIModel(m_oimodelCNO) );
            listChanges.add( new AddIncludedOIModel(m_oimodelCNOInstance) );

            m_oimodelNormMap.applyChanges( listChanges );

//        m_oimodelNormMap.applyChange(new AddIncludedOIModel(m_oimodelCNO));
//        m_oimodelNormMap.applyChange(new AddIncludedOIModel(m_oimodelCNOInstance));

    }

/*
----------------------------------- parsing methods --------------------------------------------
*/

    /**
     * Parses the concepts of this map from the associated map file.
     */
    public void parse() throws NormalisationException
    {
        try {

            readNormMapModels(true);

            parseNormMap();

            parseNormMapConcepts();

            parseNormMapProperties();

            // validate();

        } catch (Exception e) {

            throw new NormalisationException("Exception while parsing Normalisation Map.", e);

        }

    }

    private void parseNormMap() throws Exception
    {
        Set setConcepts = m_oimodelNormMap.getConcepts();

        // the mapping instance
        Instance instanceNormMap = Parsing.readUniqueConceptInstance(m_oimodelNormMap, CNOVocabulary.URI_CNO_NORM_MAP, CNOErrors.ERROR_ONE_AND_ONLY_ONE_MAPPING);

        // the mapping name
        m_strURINormMap = instanceNormMap.getURI();
        //System.out.println(m_strURINormMap);

        // the source ontology
        m_strURIXSDocument = Parsing.readUniquePropertyValue(instanceNormMap, CNOVocabulary.URI_CNO_RELATES_XS_DOCUMENT, CNOErrors.ERROR_ONE_AND_ONLY_ONE_SOURCE_ONTOLOGY);

        // the target ontology
        m_strURIOntology = Parsing.readUniquePropertyValue(instanceNormMap, CNOVocabulary.URI_CNO_RELATES_ONTOLOGY, CNOErrors.ERROR_ONE_AND_ONLY_ONE_TARGET_ONTOLOGY);
    }


    private void parseNormMapConcepts() throws Exception
    {
        // ConceptBridge instances
        m_mapNodeBridges = Parsing.readAllConceptInstances(m_oimodelNormMap, CNOVocabulary.URI_CNO_NODE_BRIDGE, null);

        // PropertyBridge instances
        m_mapPathBridges = Parsing.readAllConceptInstances(m_oimodelNormMap, CNOVocabulary.URI_CNO_PATH_BRIDGE,	null);

        // PropertyNode instances
        m_mapPropertyNodes = Parsing.readAllConceptInstances(m_oimodelNormMap, CNOVocabulary.URI_CNO_PROPERTY_NODE,	null);

/* for the future use
		// AttibutePath instances
		m_mapAttributePaths = Parsing.readAllConceptInstances(m_oimodelNormMap, CNOVocabulary.URI_CNO_ATTRIBUTE_PATH, null);

		// RelationPath instances
		m_mapRelationPaths = Parsing.readAllConceptInstances(m_oimodelNormMap, CNOVocabulary.URI_CNO_RELATION_PATH, null);
*/
    }

    private void parseNormMapProperties() throws Exception
    {
        parsePropertyNodesProperties();
        parseNodeBridgesProperties();
        parsePathBridgesProperties();
    }

    private void parseNodeBridgesProperties() throws Exception
    {
        Iterator i = m_mapNodeBridges.entrySet().iterator();

        for(; i.hasNext(); ) {

            Map.Entry me = (Map.Entry) i.next();

            Instance instanceNB = (Instance) me.getValue();

            NodeBridge newNB = new NodeBridge(this, instanceNB);

            newNB.parse();

            String strURINB = (String) me.getKey();

            m_mapNodeBridges.put(strURINB, newNB);
        }
    }

    private void parsePathBridgesProperties() throws Exception
    {
        Iterator i = m_mapPathBridges.entrySet().iterator();

        for(; i.hasNext(); ) {

	    Map.Entry me = (Map.Entry) i.next();

            Instance instancePB = (Instance) me.getValue();

            PathBridge newPB = new PathBridge(this, instancePB);

            newPB.parse();

            String strURIPB = (String) me.getKey();

            m_mapPathBridges.put(strURIPB, newPB);
        }
    }

    private void parsePropertyNodesProperties() throws Exception
    {
        Iterator i = m_mapPropertyNodes.entrySet().iterator();

        for(; i.hasNext(); ) {

            Map.Entry me = (Map.Entry) i.next();

            Instance instancePropertyNode = (Instance) me.getValue();

            PropertyNode newPropertyNode = new PropertyNode(this, instancePropertyNode);

            newPropertyNode.parse();

            String strURIPropertyNode = (String) me.getKey();

            m_mapPropertyNodes.put(strURIPropertyNode, newPropertyNode);
        }
    }


/*
----------------------------------- methods for manipulating the norm map --------------------------------------------
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -