diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java index f66f014..b353dd1 100644 --- a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java +++ b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java @@ -719,8 +719,10 @@ public class ConfigurationWindow extends JFrame { configuration.put("outputFile", tf_OutputFile); tf_OutputFile.setColumns(10); - String[] types = {"статья ЭФЭ","статья энциклопедии", "книга", "журнал"}; + String[] types = {"elenphArticle", "encArticle", "book", "journal"}; JComboBox cbox_type = new JComboBox(types); + configuration.put("rdf_type", cbox_type); + JLabel lb_type = new JLabel("Type"); diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/ConversionExecutor.java b/src/main/java/pro/litvinovg/w2phtml/gui/ConversionExecutor.java index 33dbf94..cc4aff1 100644 --- a/src/main/java/pro/litvinovg/w2phtml/gui/ConversionExecutor.java +++ b/src/main/java/pro/litvinovg/w2phtml/gui/ConversionExecutor.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Set; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -46,6 +47,8 @@ public class ConversionExecutor { optionValue = Boolean.toString(((JCheckBox) component).isSelected()); } else if (component.getClass().equals(JLabel.class)) { optionValue = ((JLabel) component).getText(); + } else if (component.getClass().equals(JComboBox.class)) { + optionValue = ((JComboBox) component).getSelectedItem().toString(); } options.put(optionName, optionValue); diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/resources/epub.png b/src/main/java/pro/litvinovg/w2phtml/gui/resources/epub.png new file mode 100644 index 0000000..e6f614f Binary files /dev/null and b/src/main/java/pro/litvinovg/w2phtml/gui/resources/epub.png differ diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/resources/html.png b/src/main/java/pro/litvinovg/w2phtml/gui/resources/html.png new file mode 100644 index 0000000..9a58f12 Binary files /dev/null and b/src/main/java/pro/litvinovg/w2phtml/gui/resources/html.png differ diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/resources/rdf.png b/src/main/java/pro/litvinovg/w2phtml/gui/resources/rdf.png new file mode 100644 index 0000000..e4389ac Binary files /dev/null and b/src/main/java/pro/litvinovg/w2phtml/gui/resources/rdf.png differ diff --git a/src/main/java/w2phtml/rdf/DocumentStructure.java b/src/main/java/w2phtml/rdf/DocumentStructure.java index 6730f96..45a1983 100644 --- a/src/main/java/w2phtml/rdf/DocumentStructure.java +++ b/src/main/java/w2phtml/rdf/DocumentStructure.java @@ -14,47 +14,55 @@ import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; import org.apache.jena.vocabulary.*; +import w2phtml.xhtml.XhtmlConfig; import w2phtml.xhtml.XhtmlDocument; import org.apache.jena.rdf.model.Property; public class DocumentStructure { + private static final String HTML_EXCERPT_PROPERTY = "htmlExcerpt"; private static final String TOCITEM = "TOCItem"; - private HashMap elements; - private HashMap inputParts; - private final String TS = "https://iph.ras.ru/text_structures#"; - private final String PARSERNAME = "w2phtml"; - private final String EXCERPT = "elenphExcerpt"; - private final String TOC_ELEMENT = "TOCElement"; - private final String ELENPHARTICLE = "elenphArticle"; - private String documentID = "DOC_ID"; - - + private static final String TS = "https://litvinovg.pro/text_structures#"; + private static final String PARSERNAME = "w2phtml"; + private static final String TEXT_EXCERPT = "textExcerpt"; + private static final String TOC_LEVEL = "TOCLevel"; + private static final String TABLE_OF_CONTENTS = "TOC"; + private static final String PUBLICATION = "publication"; + private static final String BOOK = "book"; + private static final String JOURNAL = "journal"; + private static final String ENC_ARTICLE = "encArticle"; + private static final String ELENPH_ARTICLE = "elenphArticle"; + private static final String ELENPH_EXCERPT = "elenphExcerpt"; + + private String docID = "DOC_ID"; + private String documentType = "elenphArticle"; + private String excerptType = "elenphExcerpt"; + private OntModel m; private OntModel textOntology; private OntClass excerptClass; - private OntClass elementClass; + private OntClass tocLevelClass; private OntClass itemClass; - private OntClass elenphClass; + private OntClass documentClass; + private OntClass tocClass; + + private HashMap tocLevels; + private HashMap inputParts; - private DocumentStructure() { - this.elements = new HashMap(); + public DocumentStructure(Vector files,String fileName, XhtmlConfig config) { + this.tocLevels = new HashMap(); this.inputParts = new HashMap(); this.m = ModelFactory.createOntologyModel(); this.textOntology = ModelFactory.createOntologyModel(); - //textOntology.read(DocumentStructure.class.getResource("/w2phtml/rdf/resources/text_structures.rdf").toString()); - this.excerptClass = textOntology.createClass(TS + EXCERPT); - this.elementClass = textOntology.createClass(TS + TOC_ELEMENT); + this.tocLevelClass = textOntology.createClass(TS + TOC_LEVEL); + this.tocClass = textOntology.createClass(TS + TABLE_OF_CONTENTS); this.itemClass = textOntology.createClass(TS + TOCITEM); - this.elenphClass = textOntology.createClass(TS + ELENPHARTICLE); - - - - } - public DocumentStructure(Vector files,String fileName) { - this(); - this.documentID = fileName; + this.docID = fileName; + String publicationType = config.getRDFType(); + setPublicationType(publicationType); + this.documentClass = textOntology.createClass(TS + documentType); + this.excerptClass = textOntology.createClass(TS + excerptType); for(int i = 0 ; i< files.size();i++) { XhtmlDocument inputDoc = files.get(i); DocumentPart part = new DocumentPart(inputDoc); @@ -64,6 +72,23 @@ public class DocumentStructure { addEmptyParts(); } + private void setPublicationType(String publicationType) { + + if (publicationType.equals(documentType)) { + this.documentType = ELENPH_ARTICLE; + this.excerptType = ELENPH_EXCERPT; + } else if (publicationType.equals(BOOK)){ + this.documentType = BOOK; + this.excerptType = TEXT_EXCERPT; + } else if (publicationType.equals(JOURNAL)){ + this.documentType = JOURNAL; + this.excerptType = TEXT_EXCERPT; + } else if (publicationType.equals(ENC_ARTICLE)){ + this.documentType = ENC_ARTICLE; + this.excerptType = TEXT_EXCERPT; + } + } + private void addEmptyParts() { Set paths = inputParts.keySet(); String[] array = new String[paths.size()]; @@ -122,30 +147,38 @@ public class DocumentStructure { } private Resource createExcerpt(DocumentPart docExcerpt) { - String name = TS + EXCERPT + "/" + PARSERNAME + "_" + documentID + docExcerpt.getSafePath(); - Resource excerpt = m.createIndividual(name, excerptClass); + String excerptName = TS + excerptType + "/" + PARSERNAME + "_" + docID + docExcerpt.getSafePath(); + Resource excerpt = m.createIndividual(excerptName, excerptClass); if (!docExcerpt.getBody().isEmpty()) { - Property htmlExcerpt = m.createProperty(TS + "htmlExcerpt"); + Property htmlExcerpt = m.createProperty(TS + HTML_EXCERPT_PROPERTY); excerpt.addLiteral(htmlExcerpt, docExcerpt.getBody()); } return excerpt; } - private void createElement(DocumentPart docPart) { - String elementName = TS + TOC_ELEMENT + "/" + PARSERNAME + "_" + documentID + docPart.getSafePath(); - Resource element = m.createIndividual(elementName,elementClass); - element.addProperty( RDFS.label, docPart.getName()); - elements.put(docPart.getPath(), element); - attachExcerpt(docPart, element); + private void createTOCLevel(DocumentPart docPart) { + String levelName = TS + TOC_LEVEL + "/" + PARSERNAME + "_" + docID + docPart.getSafePath(); + Resource level = m.createIndividual(levelName,tocLevelClass); + level.addProperty( RDFS.label, docPart.getName()); + tocLevels.put(docPart.getPath(), level); + attachExcerpt(docPart, level); } - private void createDocumentElement(DocumentPart docPart) { - String elementName = TS + ELENPHARTICLE + "/" + PARSERNAME + "_" + documentID ; - Resource element = m.createResource(elementName,elenphClass); - element.addProperty( RDFS.label, docPart.getName()); - addMetadataProperties(element,docPart.getMetadata()); - elements.put(docPart.getPath(), element); - attachExcerpt(docPart, element); + private void createDocument(DocumentPart docPart) { + String documentURI = TS + documentType + "/" + PARSERNAME + "_" + docID ; + Resource document = m.createResource(documentURI, documentClass); + document.addProperty( RDFS.label, docPart.getName()); + String tocURI = TS + TABLE_OF_CONTENTS + "/" + PARSERNAME + "_" + docID ; + + Resource toc = m.createResource(tocURI, tocClass); + toc.addProperty( RDFS.label, docPart.getName()); + + Property hasTOC = m.createProperty(TS + "hasTOC"); + document.addProperty(hasTOC, toc); + + addMetadataProperties(document, docPart.getMetadata()); + tocLevels.put(docPart.getPath(), toc); + attachExcerpt(docPart, toc); } private void addMetadataProperties(Resource resource, HashMap> metadata) { @@ -185,7 +218,7 @@ public class DocumentStructure { private boolean isDefinedInOntology(Resource resource, String name) { String nameSpace = resource.getNameSpace(); - if (nameSpace.contains(TS + EXCERPT)) { + if (nameSpace.contains(TS + excerptType)) { if (name.equals("author") || name.equals("bibliography") || name.equals("keywords") || @@ -195,7 +228,7 @@ public class DocumentStructure { return true; } } else - if (nameSpace.contains(TS + ELENPHARTICLE)) { + if (nameSpace.contains(TS + documentType)) { if (name.equals("doi") || name.equals("firstPublication") || //name.equals("yearAndMonth") || @@ -239,16 +272,16 @@ public class DocumentStructure { return true; } private void createTOCItem(DocumentPart docPart) { - String tocItemName = TS + TOCITEM + "/" + PARSERNAME + "_" + documentID + docPart.getSafePath(); + String tocItemName = TS + TOCITEM + "/" + PARSERNAME + "_" + docID + docPart.getSafePath(); Resource tocItem = m.createIndividual(tocItemName,itemClass); tocItem.addProperty( RDFS.label, docPart.getName()); Property pointsTo = m.createProperty(TS + "pointsTo"); Property itemNumber = m.createProperty(TS + "itemNumber"); Property hasTOCItem = m.createProperty(TS + "hasTOCItem"); tocItem.addLiteral(itemNumber, docPart.getNumber()); - m.add(tocItem, pointsTo, elements.get(docPart.getPath())); + m.add(tocItem, pointsTo, tocLevels.get(docPart.getPath())); if (!docPart.getPath().isEmpty()) { - Resource parent = elements.get(docPart.getParentPath()); + Resource parent = tocLevels.get(docPart.getParentPath()); m.add(parent, hasTOCItem, tocItem); } @@ -290,9 +323,9 @@ public class DocumentStructure { for (String path : paths) { DocumentPart part = inputParts.get(path); if (part.getPath().isEmpty()) { - createDocumentElement(part); + createDocument(part); } else { - createElement(part); + createTOCLevel(part); } } } diff --git a/src/main/java/w2phtml/rdf/RDFDocumentResult.java b/src/main/java/w2phtml/rdf/RDFDocumentResult.java index a16b8d8..58a9089 100644 --- a/src/main/java/w2phtml/rdf/RDFDocumentResult.java +++ b/src/main/java/w2phtml/rdf/RDFDocumentResult.java @@ -21,9 +21,10 @@ public class RDFDocumentResult implements OutputFile { public RDFDocumentResult(Vector outFiles, String fileName, XhtmlConfig config) { + System.out.println("FILENAME "+ fileName); this.sFileName = Misc.removeExtension(fileName); this.config = config; - rdfStructure = new DocumentStructure(outFiles,fileName); + rdfStructure = new DocumentStructure(outFiles,sFileName,config); Metadata metadata = new Metadata(); metadata.read(config.getCSVMetadataFile()); rdfStructure.applyMetadata(metadata); diff --git a/src/main/java/w2phtml/rdf/resources/text_structures.rdf b/src/main/java/w2phtml/rdf/resources/text_structures.rdf index 7a02817..f29d37a 100644 --- a/src/main/java/w2phtml/rdf/resources/text_structures.rdf +++ b/src/main/java/w2phtml/rdf/resources/text_structures.rdf @@ -1,272 +1,365 @@ - - ts_ - Text structures + xmlns:search="https://dideside.com/searchOntology#" + xmlns:foaf="http://xmlns.com/foaf/0.1/"> + + ts + Text structures Ontology - - -1 + + + + - + + -1 + -1 + Book + + + Table of contents + -1 -1 - - - Electronic philosophical encyclopedia article + + - + - - - - - TOC Element + + Publication -1 - -1 + + + + + + Encyclopedia article + + + + -1 + -1 + + + + TOC Item + + + + + + + + + + elenphExcerpt.ftl + + + + + + Elenph Excerpt + + + + + elenphAritcle.ftl + Electronic philosophical encyclopedia article + + + + + + + + Text excerpt + + + + + + + + + Journal + -1 + -1 + + + + + + + + Table of contents element - - - - - - + TOC Level + - Text excerpt - - - - - -1 - Elenph Excerpt - -1 - + + - + has TOC item - - - - has TOC item + - - - - - - true + + + + + has TOC + + + + + + + true + + + + + + has text + + + + true + + + - - First publication + + + points to - - - - - - - - - Year and month - - - - - - - - - - - - - + - - - - Works - - + + + true + + + + author + + - - - - bibliography - + + + + + + + + + Works + + + + + + + + + + DOI + + + + + + + + + + - - + First publication + + + + Keywords + + + + + + + + + + + HTML - + - html Excerpt + + + + + html Excerpt + + + Year and month + + + + + + + + - - - - - + + - + + + + + - Issue - + Affiliation - - + + - htmlExcerpt - - - - - - - - + + bibliography - - - Affiliation - - + - - - - - - + + - - - author - - - - - - - - - Keywords - - - - - - - - - - - - DOI - - - - - - points to - - - - - - true - - - - - - - - - - - - - true - - has text - - - - - - - Item Number - - - - - - - - - - - Year + Year + + + + + + + + + + Issue + + + + + + + + + + + + - - + + + htmlExcerpt + + + + + - + Item Number + + + + + + diff --git a/src/main/java/w2phtml/xhtml/XhtmlConfig.java b/src/main/java/w2phtml/xhtml/XhtmlConfig.java index 410666d..347343c 100644 --- a/src/main/java/w2phtml/xhtml/XhtmlConfig.java +++ b/src/main/java/w2phtml/xhtml/XhtmlConfig.java @@ -40,7 +40,7 @@ import w2phtml.util.Misc; public class XhtmlConfig extends w2phtml.base.ConfigBase { // Implement configuration methods - protected int getOptionCount() { return 64; } + protected int getOptionCount() { return 65; } protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; } // Override setOption: To be backwards compatible, we must accept options @@ -163,6 +163,7 @@ public class XhtmlConfig extends w2phtml.base.ConfigBase { private static final int MIN_LETTER_SPACING = 61; private static final int PAGE_BREAK_STYLE = 62; private static final int ANNOTATION_METADATA = 63; + private static final int RDF_TYPE = 64; protected ComplexOption xheading = addComplexOption("heading-map"); protected ComplexOption xpar = addComplexOption("paragraph-map"); @@ -291,6 +292,8 @@ public class XhtmlConfig extends w2phtml.base.ConfigBase { options[MIN_LETTER_SPACING] = new Option("min_letter_spacing","0.15"); options[PAGE_BREAK_STYLE] = new Option("page_break_style",""); options[CSV_METADATA] = new Option("csv_metadata",""); + options[RDF_TYPE] = new Option("rdf_type","elenphArticle"); + options[CSS_INLINE] = new BooleanOption("css_inline","true"); options[ALIGN_SPLITS_TO_PAGES] = new BooleanOption("align_splits_to_pages","false"); @@ -440,6 +443,8 @@ public class XhtmlConfig extends w2phtml.base.ConfigBase { public String getXhtmlDirectoryIcon() { return options[DIRECTORY_ICON].getString(); } public String getXhtmlDocumentIcon() { return options[DOCUMENT_ICON].getString(); } public String getCSVMetadataFile() { return options[CSV_METADATA].getString(); } + public String getRDFType() { return options[RDF_TYPE].getString(); } + public boolean getGreenstoneSeparation() { if ( ((IntegerOption) options[SPLIT_LEVEL]).getValue() != 0) { diff --git a/src/main/oxt2/description.xml b/src/main/oxt2/description.xml index b6d973e..4ec5768 100644 --- a/src/main/oxt2/description.xml +++ b/src/main/oxt2/description.xml @@ -3,7 +3,7 @@ - +