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

📄 d_normalisation_xml2rdfimpl.java

📁 normkit is a set of tools supporting ontology learning. from xml,xsd to rdfs.
💻 JAVA
字号:
package it.itc.ectrl.normkit.dnorm_xml2rdf.impl;

//import java.util.*;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URI;
/*
import edu.unika.aifb.kaon.api.*;
import edu.unika.aifb.kaon.api.change.*;
import edu.unika.aifb.kaon.api.oimodel.*;
import edu.unika.aifb.kaon.api.vocabulary.*;

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

import edu.unika.aifb.rdf.api.util.*;
import edu.unika.aifb.rdf.api.model.*;
*/
import org.w3c.dom.Document;
import org.w3c.dom.Node;
/*
import org.xml.sax.InputSource;

import org.apache.xml.dtm.ref.dom2dtm.DOM2DTM;
import org.apache.xml.dtm.ref.DTMManagerDefault;
import org.apache.xml.dtm.DTMManager;
import org.apache.xpath.objects.XMLStringFactoryImpl;

import javax.xml.parsers.DocumentBuilderFactory;
*/
import it.itc.ectrl.normkit.common.*;
import it.itc.ectrl.normkit.common.NormMapModel.*;
import it.itc.ectrl.normkit.dnorm_xml2rdf.api.D_Normalisation_XML2RDF;





import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
//import javax.xml.transform.Templates;
//import javax.xml.transform.stream.StreamSource;
//import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.sax.SAXResult;
//import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TemplatesHandler;
import javax.xml.transform.sax.TransformerHandler;

import org.xml.sax.XMLReader;
import org.xml.sax.ContentHandler;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLReaderFactory;

import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.templates.OutputProperties;





/**
 * Implements D-Normalisation process for XML->RDF transformation.
 * @author Oliver Fodor (fodor@itc.it)
 */
public class D_Normalisation_XML2RDFImpl implements D_Normalisation_XML2RDF {
    /**
     * Source XML govering Schema location.
     */
    String m_strSourceXSDPhysicalURI;

    /**
     * Physical location of target ontology.
     */
    String m_strTargetOntologyPhysicalURI;

    /**
     * Physical location of target RDF file.
     */
    String m_strTargetInstancesPhysicalURI;

    // logical
    /**
     * Logical URI of source governing XML Schema.
     */
    String m_strURISourceXSDocument;

    /**
     * Logical URI of target ontology.
     */
    String m_strURITargetOntology;

    /**
     * Governing Normalisation Map.
     */
    NormMap m_normmap;

    String m_strSourceXMLDocumentURI;

    XMLReader m_inputXMLReader;

    /**
     * Transformation table encompassing information about currently translated instances.
     */
    D_NormalisationTable m_transformationTable = new D_NormalisationTable();

    /**
     * Creates an instance of this class and associates it with source, target and governing map documents.
     * @param sourceXMLPath physical location of source XML instance file
     * @param targetRDFPath physical location for output RDF document
     * @param targetOntologyPath physical location of ontology for the target instances
     * @param normMapPath physical location of Normalisation Map governing this process
     */
    public D_Normalisation_XML2RDFImpl(String sourceXMLPath, String targetRDFPath, String targetOntologyPath, String normMapPath) throws NormalisationException {

//        try {

//            sourceXMLPath = new URL( sourceXMLPath ).getFile();
//            m_isSourceXMLDocument = new FileInputStream(sourceXMLPath);

        m_normmap = new NormMap(normMapPath);
        m_strTargetInstancesPhysicalURI = targetRDFPath;
        m_strTargetOntologyPhysicalURI = targetOntologyPath;
        m_strSourceXMLDocumentURI = sourceXMLPath;

//        run();

        initialize();
  //      prepareModels();
//        } catch (Exception e) {

//            throw new NormalisationException("Exception while reading XML source.", e);

//        }

    }



    public void run () throws NormalisationException {

        try {
            // Parse the XML input document.
            m_inputXMLReader.parse(m_strSourceXMLDocumentURI);

        } catch (Exception e) {
            throw new NormalisationException("Exception while parsing and transforming XML source.", e);
        }


    }

    private void initialize()  throws NormalisationException {

        try {
            Document xslDocument = m_normmap.compileToXSLSheet();

            DOMSource xslDomSource = new DOMSource(xslDocument);

            // Set the systemId: note this is actually a URL, not a local filename
            xslDomSource.setSystemId("file://temporaryXSLTNormMap.xsl");

            TransformerFactory tFactory = TransformerFactory.newInstance();

            SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);

            TransformerHandler handler = saxTFactory.newTransformerHandler(xslDomSource);

            Transformer t = handler.getTransformer();

            t.setParameter("baseURIparam", m_strTargetInstancesPhysicalURI);


            // Create an XMLReader and set its ContentHandler.
            XMLReader reader = XMLReaderFactory.createXMLReader();
            reader.setContentHandler(handler);

            // Set the ContentHandler to also function as a LexicalHandler, which
            // includes "lexical" events (e.g., comments and CDATA).
            reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);

            File targetFile = new File(new URI(m_strTargetInstancesPhysicalURI));

            targetFile.createNewFile();

            FileOutputStream fos = new FileOutputStream(targetFile);

            Serializer serializer = SerializerFactory.getSerializer(OutputProperties.getDefaultMethodProperties("xml"));

            serializer.setOutputStream(fos);

            // Set the result handling to be a serialization to the file output stream.
            Result result = new SAXResult(serializer.asContentHandler());

            handler.setResult(result);

            m_inputXMLReader = reader;

        } catch (Exception e) {

            throw new NormalisationException("Exception while initializing XSLT transformation.", e);

        }
    }
/*
----------------------------------- setters and getters --------------------------------------------
*/

    /**
     * Returns the governing Normalisation Map.
     */
    public NormMap getNormMap () {

        return m_normmap;
    }

}

⌨️ 快捷键说明

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