From 3c0519cc22fc3fb0570fc59da3dbd7b329e80d5f Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Fri, 28 Feb 2020 13:56:03 +0100 Subject: [PATCH] Set ouput --- .../writer2latex/rdf/DocumentStructure.java | 16 +++++------ .../java/writer2latex/rdf/RDFConverter.java | 20 +++----------- ...{RDFWriter.java => RDFDocumentResult.java} | 27 +++++++++---------- 3 files changed, 24 insertions(+), 39 deletions(-) rename src/main/java/writer2latex/rdf/{RDFWriter.java => RDFDocumentResult.java} (61%) diff --git a/src/main/java/writer2latex/rdf/DocumentStructure.java b/src/main/java/writer2latex/rdf/DocumentStructure.java index 052a5ba..f388fe1 100644 --- a/src/main/java/writer2latex/rdf/DocumentStructure.java +++ b/src/main/java/writer2latex/rdf/DocumentStructure.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.io.OutputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Set; @@ -28,10 +29,11 @@ public class DocumentStructure { private HashMap inputParts; private final String TS = "https://iph.ras.ru/text_structures#"; private final String PARSERNAME = "w2phtml"; - private final String EXCERPT = "Excerpt"; + private final String EXCERPT = "textExcerpt"; private final String TOC_ELEMENT = "TOCElement"; private final String ELENPHARTICLE = "elenphArticle"; - private String documentID = "DOC_ID"; + private String documentID = "12DOC_ID"; + private OntModel m; private OntClass excerptClass; @@ -90,13 +92,8 @@ public class DocumentStructure { } return emptyPath.toString(); } - public void printModel() { - m.write(System.out, "RDF/XML-ABBREV"); - } - + public void printModel(String fileName) { - //RDFWriter writer = m.getWriter(); - //writer.setProperty("showXmlDeclaration","true"); File outFile = new File(fileName + ".rdf"); FileWriter fw = null; try { @@ -117,6 +114,9 @@ public class DocumentStructure { } } + public void printModel(OutputStream os) { + m.write(os,"RDF/XML-ABBREV"); + } private void addPart(DocumentPart docExcerpt) { diff --git a/src/main/java/writer2latex/rdf/RDFConverter.java b/src/main/java/writer2latex/rdf/RDFConverter.java index 40a1f69..49b68a7 100644 --- a/src/main/java/writer2latex/rdf/RDFConverter.java +++ b/src/main/java/writer2latex/rdf/RDFConverter.java @@ -51,8 +51,6 @@ public final class RDFConverter extends Converter { @Override public ConverterResult convert(InputStream is, String sTargetFileName) throws IOException { setOpenPubStructure(false); ConverterResult xhtmlResult = super.convert(is, "chapter"); - createRDF(sTargetFileName); - return createPackage(xhtmlResult,sTargetFileName); } @@ -61,21 +59,11 @@ public final class RDFConverter extends Converter { return createPackage(xhtmlResult,sTargetFileName); } - - private void createRDF(String sTargetFileName) { - DocumentStructure structure = new DocumentStructure(this.outFiles); - structure.createTree(); - structure.printModel(sTargetFileName); - - } - - private ConverterResult createPackage(ConverterResult xhtmlResult, String sTargetFileName) { - ConverterResultImpl rdfResult = new ConverterResultImpl(); - RDFWriter rdfWriter = new RDFWriter(xhtmlResult,sTargetFileName,3,getXhtmlConfig()); - rdfResult.addDocument(rdfWriter); - rdfResult.setMetaData(xhtmlResult.getMetaData()); - return rdfResult; + ConverterResultImpl rdfConverterResult = new ConverterResultImpl(); + RDFDocumentResult rdfDocument = new RDFDocumentResult(this.outFiles,sTargetFileName,getXhtmlConfig()); + rdfConverterResult.addDocument(rdfDocument); + return rdfConverterResult; } } \ No newline at end of file diff --git a/src/main/java/writer2latex/rdf/RDFWriter.java b/src/main/java/writer2latex/rdf/RDFDocumentResult.java similarity index 61% rename from src/main/java/writer2latex/rdf/RDFWriter.java rename to src/main/java/writer2latex/rdf/RDFDocumentResult.java index e6ac21f..00b95c8 100644 --- a/src/main/java/writer2latex/rdf/RDFWriter.java +++ b/src/main/java/writer2latex/rdf/RDFDocumentResult.java @@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Iterator; +import java.util.Vector; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -11,30 +12,33 @@ import writer2latex.api.ConverterResult; import writer2latex.api.OutputFile; import writer2latex.util.Misc; import writer2latex.xhtml.XhtmlConfig; +import writer2latex.xhtml.XhtmlDocument; -public class RDFWriter implements OutputFile { +public class RDFDocumentResult implements OutputFile { private ConverterResult xhtmlResult; private String sFileName; - private int nVersion; private XhtmlConfig config; + private DocumentStructure rdfStructure = null; - public RDFWriter(ConverterResult xhtmlResult, String sFileName, int nVersion, XhtmlConfig config) { - this.xhtmlResult = xhtmlResult; + public RDFDocumentResult(Vector outFiles, String sFileName, XhtmlConfig config) { this.sFileName = Misc.removeExtension(sFileName); - this.nVersion = nVersion; this.config = config; + rdfStructure = new DocumentStructure(outFiles); + rdfStructure.createTree(); + } + @Override public String getFileName() { return sFileName+".rdf"; } @Override public String getMIMEType() { - return "application/epub+zip"; + return "rdf"; } @Override public boolean isMasterDocument() { @@ -42,18 +46,11 @@ public class RDFWriter implements OutputFile { } @Override public boolean containsMath() { - // We don't really care about this - return nVersion==3; + return false; } @Override public void write(OutputStream os) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - // Finally XHTML content - Iterator iter = xhtmlResult.iterator(); - while (iter.hasNext()) { - OutputFile excerptFile = iter.next(); - } + rdfStructure.printModel(os); } }