Set ouput

This commit is contained in:
Georgy Litvinov 2020-02-28 13:56:03 +01:00
parent 30110ee2af
commit 3c0519cc22
3 changed files with 24 additions and 39 deletions

View file

@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -28,10 +29,11 @@ public class DocumentStructure {
private HashMap<String, DocumentPart> inputParts; private HashMap<String, DocumentPart> inputParts;
private final String TS = "https://iph.ras.ru/text_structures#"; private final String TS = "https://iph.ras.ru/text_structures#";
private final String PARSERNAME = "w2phtml"; private final String PARSERNAME = "w2phtml";
private final String EXCERPT = "Excerpt"; private final String EXCERPT = "textExcerpt";
private final String TOC_ELEMENT = "TOCElement"; private final String TOC_ELEMENT = "TOCElement";
private final String ELENPHARTICLE = "elenphArticle"; private final String ELENPHARTICLE = "elenphArticle";
private String documentID = "DOC_ID"; private String documentID = "12DOC_ID";
private OntModel m; private OntModel m;
private OntClass excerptClass; private OntClass excerptClass;
@ -90,13 +92,8 @@ public class DocumentStructure {
} }
return emptyPath.toString(); return emptyPath.toString();
} }
public void printModel() {
m.write(System.out, "RDF/XML-ABBREV");
}
public void printModel(String fileName) { public void printModel(String fileName) {
//RDFWriter writer = m.getWriter();
//writer.setProperty("showXmlDeclaration","true");
File outFile = new File(fileName + ".rdf"); File outFile = new File(fileName + ".rdf");
FileWriter fw = null; FileWriter fw = null;
try { try {
@ -117,6 +114,9 @@ public class DocumentStructure {
} }
} }
public void printModel(OutputStream os) {
m.write(os,"RDF/XML-ABBREV");
}
private void addPart(DocumentPart docExcerpt) { private void addPart(DocumentPart docExcerpt) {

View file

@ -51,8 +51,6 @@ public final class RDFConverter extends Converter {
@Override public ConverterResult convert(InputStream is, String sTargetFileName) throws IOException { @Override public ConverterResult convert(InputStream is, String sTargetFileName) throws IOException {
setOpenPubStructure(false); setOpenPubStructure(false);
ConverterResult xhtmlResult = super.convert(is, "chapter"); ConverterResult xhtmlResult = super.convert(is, "chapter");
createRDF(sTargetFileName);
return createPackage(xhtmlResult,sTargetFileName); return createPackage(xhtmlResult,sTargetFileName);
} }
@ -61,21 +59,11 @@ public final class RDFConverter extends Converter {
return createPackage(xhtmlResult,sTargetFileName); 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) { private ConverterResult createPackage(ConverterResult xhtmlResult, String sTargetFileName) {
ConverterResultImpl rdfResult = new ConverterResultImpl(); ConverterResultImpl rdfConverterResult = new ConverterResultImpl();
RDFWriter rdfWriter = new RDFWriter(xhtmlResult,sTargetFileName,3,getXhtmlConfig()); RDFDocumentResult rdfDocument = new RDFDocumentResult(this.outFiles,sTargetFileName,getXhtmlConfig());
rdfResult.addDocument(rdfWriter); rdfConverterResult.addDocument(rdfDocument);
rdfResult.setMetaData(xhtmlResult.getMetaData()); return rdfConverterResult;
return rdfResult;
} }
} }

View file

@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -11,30 +12,33 @@ import writer2latex.api.ConverterResult;
import writer2latex.api.OutputFile; import writer2latex.api.OutputFile;
import writer2latex.util.Misc; import writer2latex.util.Misc;
import writer2latex.xhtml.XhtmlConfig; import writer2latex.xhtml.XhtmlConfig;
import writer2latex.xhtml.XhtmlDocument;
public class RDFWriter implements OutputFile { public class RDFDocumentResult implements OutputFile {
private ConverterResult xhtmlResult; private ConverterResult xhtmlResult;
private String sFileName; private String sFileName;
private int nVersion;
private XhtmlConfig config; private XhtmlConfig config;
private DocumentStructure rdfStructure = null;
public RDFWriter(ConverterResult xhtmlResult, String sFileName, int nVersion, XhtmlConfig config) { public RDFDocumentResult(Vector<XhtmlDocument> outFiles, String sFileName, XhtmlConfig config) {
this.xhtmlResult = xhtmlResult;
this.sFileName = Misc.removeExtension(sFileName); this.sFileName = Misc.removeExtension(sFileName);
this.nVersion = nVersion;
this.config = config; this.config = config;
rdfStructure = new DocumentStructure(outFiles);
rdfStructure.createTree();
} }
@Override public String getFileName() { @Override public String getFileName() {
return sFileName+".rdf"; return sFileName+".rdf";
} }
@Override public String getMIMEType() { @Override public String getMIMEType() {
return "application/epub+zip"; return "rdf";
} }
@Override public boolean isMasterDocument() { @Override public boolean isMasterDocument() {
@ -42,18 +46,11 @@ public class RDFWriter implements OutputFile {
} }
@Override public boolean containsMath() { @Override public boolean containsMath() {
// We don't really care about this return false;
return nVersion==3;
} }
@Override public void write(OutputStream os) throws IOException { @Override public void write(OutputStream os) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); rdfStructure.printModel(os);
// Finally XHTML content
Iterator<OutputFile> iter = xhtmlResult.iterator();
while (iter.hasNext()) {
OutputFile excerptFile = iter.next();
}
} }
} }