Added metadata conversion to RDF

This commit is contained in:
Georgy Litvinov 2020-04-22 20:19:43 +02:00
parent d0d991c061
commit 117b864e63
5 changed files with 45 additions and 9 deletions

View file

@ -1,3 +1,3 @@
#Wed Apr 22 15:32:34 CEST 2020
#Wed Apr 22 20:17:51 CEST 2020
releaseVersion=0.5.7
releaseDate=15\:32\:34 22-04-2020
releaseDate=20\:17\:51 22-04-2020

View file

@ -2,6 +2,7 @@ package w2phtml.rdf;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import javax.xml.transform.OutputKeys;
@ -15,11 +16,13 @@ import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
import w2phtml.util.Misc;
import w2phtml.xhtml.XhtmlDocument;
public class DocumentPart {
@ -41,8 +44,40 @@ public class DocumentPart {
extractNumber();
extractBody();
calculateParentPath();
extractAnnotationMetadata();
}
private void extractAnnotationMetadata() {
metadata = new HashMap<String,Set<String>>();
if (excerptDoc == null) {
System.out.println("Error. Excerpt doc is null!");
return;
}
Element head = excerptDoc.getHeadNode();
if (head == null) {
System.out.println("Error. Head node is null!");
return;
}
NodeList metas = head.getElementsByTagName("meta");
for (int i = 0; i < metas.getLength();i++) {
Node meta = metas.item(i);
if (Misc.isElement(meta)) {
Element metaElements = (Element) meta;
if (metaElements.hasAttribute("name") && metaElements.hasAttribute("content")) {
String metaName = metaElements.getAttribute("name");
String metaValue = metaElements.getAttribute("content");
if (metadata.containsKey(metaName)) {
metadata.get(metaName).add(metaValue);
} else {
Set<String> names = new HashSet<String>();
names.add(metaValue);
metadata.put(metaName, names);
}
}
}
}
}
public DocumentPart(String path) {
metadata = new HashMap<String,Set<String>>();
this.path = path;
this.name = "";
extractNumber();
@ -103,11 +138,7 @@ public class DocumentPart {
this.metadata = metadata;
}
public HashMap<String,Set<String>> getMetadata(){
if (metadata == null) {
return new HashMap<String,Set<String>>();
} else {
return metadata;
}
return metadata;
}
private void extractPath() {

View file

@ -194,7 +194,7 @@ public class DocumentStructure {
}
}
System.out.println(resource.getNameSpace() + " " + name);
System.out.println("rightNamespace" + TS + EXCERPT );
System.out.println("rightNamespace " + TS + EXCERPT );
return false;
}
private String convertName(String name) {

View file

@ -252,7 +252,9 @@ public class Converter extends BasicConverter {
public L10n getL10n() { return l10n; }
public void setOpenPubStructure(boolean b) { isEPUB = true; }
public void setOpenPubStructure(boolean b) {
isEPUB = b;
}
public boolean isOPS() { return isEPUB; }

View file

@ -417,6 +417,9 @@ public class Separator {
}
public void appendMetadata(String name, String value) {
if (!greenstoneSeparation) {
return;
}
if (currentComment == null) {
System.out.println("Error. No current Comment");
return;