Mercurial > hg > IndexMetaContextualizer
changeset 0:dfce13a5f5f9
nit project!
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/index.meta/01index.meta Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,100 @@ +<resource type="MPIWG" version="2.0"> + <description/> + <archive-creation-date>04.10.2010</archive-creation-date> + <name>HSPGZ0AE</name> + <archive-path>/mpiwg/online/permanent/library/HSPGZ0AE</archive-path> + <creator>digigroup</creator> + <derived-from> + <archive-path>/mpiwg/archive/data/library/R2QPGF06</archive-path> + </derived-from> + <meta> + <lang>en</lang> + <content-type>scanned document</content-type> + <bib type="manuscript"> + <place/> + + + + <author ctx="xxx">Harriot, Thomas</author> + + <person role="author" type="person"> + <name>Harriot, Thomas</name> + <identifier type="GND">http://d-nb.info/gnd/118720473</identifier> + </person> + + + <person role="editor" type="person"> + <name>Stedall, Jacqueline</name> + <identifier type="GND">http://d-nb.info/gnd/1019195649</identifier> + </person> + <person role="editor" type="person"> + <name>Schemmel, Matthias</name> + <identifier type="GND">http://d-nb.info/gnd/123937299</identifier> + </person> + <city/> + <number_of_pages>505 Bl.</number_of_pages> + <series_volume/> + <title>Mss. 6782</title> + <number_of_volumes/> + <author>Harriot, Thomas</author> + <publisher>test</publisher> + <translator/> + <edition/> + <series_author/> + <year/> + <date/> + <series_title/> + <isbn_issn/> + </bib> + <texttool> + <text-url-path>/echo/en/Harriot_Add_MS_6782_HSPGZ0AE.xml</text-url-path> + <image>pageimg</image> + <figure>figures</figure> + <page-flow>ltr</page-flow> + <odd-scan-position>right</odd-scan-position> + <title-scan-no>1</title-scan-no> + <pagebreak>pb</pagebreak> + <display>yes</display> + <digiliburlprefix>http://echo.mpiwg-berlin.mpg.de/zogilib?</digiliburlprefix> + </texttool> + <access-conditions> + <access type="free"/> + <attribution resource="original"> + <name>British Library</name> + <url>http://www.bl.uk/index.shtml</url> + </attribution> + <attribution resource="digital-image"> + <name>British Library</name> + <url>http://www.bl.uk/index.shtml</url> + </attribution> + <attribution resource="text"> + <name>Stedall, Jacqueline</name> + <url>http://www.maths.ox.ac.uk/contact/details/stedall/</url> + </attribution> + <attribution resource="text"> + <name>Schemmel, Matthias</name> + <url>http://www.mpiwg-berlin.mpg.de/en/staff/members/schemmel</url> + </attribution> + <copyright resource="original"> + <owner> + <name>British Library</name> + <url>http://www.bl.uk/index.shtml</url> + </owner> + </copyright> + <copyright resource="digital-image"> + <owner> + <name>British Library</name> + <url>http://www.bl.uk/index.shtml</url> + </owner> + </copyright> + <copyright resource="text"> + <owner> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </owner> + <license type="cc-by-sa"/> + </copyright> + </access-conditions> + + <dri type="escidoc-test">escidoc:153332</dri><dri type="escidoc">escidoc:186920</dri><dri type="mpiwg">MPIWG:5PYT50NY</dri></meta> +</resource> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/index.meta/01index.meta.anno.xml Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?><resource type="MPIWG" version="2.0"> + <description/> + <archive-creation-date>04.10.2010</archive-creation-date> + <name>HSPGZ0AE</name> + <archive-path>/mpiwg/online/permanent/library/HSPGZ0AE</archive-path> + <creator>digigroup</creator> + <derived-from> + <archive-path>/mpiwg/archive/data/library/R2QPGF06</archive-path> + </derived-from> + <meta> + <lang>en</lang> + <content-type>scanned document</content-type> + <bib type="manuscript"> + <place context-id="0">Berlin</place> + <author context-id="1">Harriot, Thomas</author> + <person role="author" type="person"> + <name>Harriot, Thomas</name> + <identifier type="GND">http://d-nb.info/gnd/118720473</identifier> + </person> + <person role="editor" type="person"> + <name>Stedall, Jacqueline</name> + <identifier type="GND">http://d-nb.info/gnd/1019195649</identifier> + </person> + <person role="editor" type="person"> + <name>Schemmel, Matthias</name> + <identifier type="GND">http://d-nb.info/gnd/123937299</identifier> + </person> + <city context-id="2">Talca</city> + <number_of_pages>505 Bl.</number_of_pages> + <series_volume/> + <title>Mss. 6782</title> + <number_of_volumes/> + <publisher context-id="3">publisher</publisher> + <translator/> + <edition/> + <series_author/> + <year/> + <date/> + <series_title/> + <isbn_issn/> + </bib> + <texttool> + <text-url-path>/echo/en/Harriot_Add_MS_6782_HSPGZ0AE.xml</text-url-path> + <image>pageimg</image> + <figure>figures</figure> + <page-flow>ltr</page-flow> + <odd-scan-position>right</odd-scan-position> + <title-scan-no>1</title-scan-no> + <pagebreak>pb</pagebreak> + <display>yes</display> + <digiliburlprefix>http://echo.mpiwg-berlin.mpg.de/zogilib?</digiliburlprefix> + </texttool> + <access-conditions> + <access type="free"/> + <attribution resource="original"> + <name>British Library</name> + <url>http://www.bl.uk/index.shtml</url> + </attribution> + <attribution resource="digital-image"> + <name>British Library</name> + <url>http://www.bl.uk/index.shtml</url> + </attribution> + <attribution resource="text"> + <name>Stedall, Jacqueline</name> + <url>http://www.maths.ox.ac.uk/contact/details/stedall/</url> + </attribution> + <attribution resource="text"> + <name>Schemmel, Matthias</name> + <url>http://www.mpiwg-berlin.mpg.de/en/staff/members/schemmel</url> + </attribution> + <copyright resource="original"> + <owner> + <name>British Library</name> + <url>http://www.bl.uk/index.shtml</url> + </owner> + </copyright> + <copyright resource="digital-image"> + <owner> + <name>British Library</name> + <url>http://www.bl.uk/index.shtml</url> + </owner> + </copyright> + <copyright resource="text"> + <owner> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </owner> + <license type="cc-by-sa"/> + </copyright> + </access-conditions> + + <dri type="escidoc-test">escidoc:153332</dri><dri type="escidoc">escidoc:186920</dri><dri type="mpiwg">MPIWG:5PYT50NY</dri></meta> +</resource> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/index.meta/02index.meta Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8"?> + <resource type="MPIWG" version="2.0"> + <description></description> + <archive-creation-date>18.03.2013</archive-creation-date> + <name>PUBSU9QD</name> + <archive-path>/mpiwg/online/permanent/library/PUBSU9QD</archive-path> + <creator>Max Planck Institute for the History of Science, Library</creator> + <derived-from> + <archive-path>/mpiwg/archive/data/library/SZF2P707</archive-path> + </derived-from> + <media-type>image</media-type> + <meta> + <content-type>scanned document</content-type> + <lang>lat</lang> + <bib type="book"> + <author>Apian, Petrus</author> + <person role="author" type="person"> + <name>Apian, Petrus</name> + <identifier type="GND">http://d-nb.info/gnd/118645455</identifier> + </person> + <editor>Gemma Frisius, Rainer</editor> + <person role="editor" type="person"> + <name>Gemma Frisius, Rainer</name> + <identifier type="GND">http://d-nb.info/gnd/111548993</identifier> + </person> + <title>Cosmographia</title> + <year>1550</year> + <city>Antwerpiae</city> + <publisher>Bontius</publisher> + <number-of-pages>[2], 65, [1] Bl. : Ill.</number-of-pages> + <keywords type="lcsh">Cosmography - Early works to 1800</keywords> + + <keywords type="ddc">520</keywords> + + <abstract>Erstausgabe 1524 in Landshut.; Enthält: astronomische Grundlagen der Erdbeschreibung; physische Geographie (mit Beschreibung der 4 Erdteile) </abstract> + <holding-library>Max Planck Institute for the History of Science, Library</holding-library> + <call-number>Rara A642c</call-number> + </bib> + <image-acquisition> + <image-type>rgb</image-type> + </image-acquisition> + <acquisition> + <provider> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </provider> + </acquisition> + <access-conditions> + <access type="free"/> + <attribution resource="original"> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </attribution> + <attribution resource="digital-image"> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </attribution> + <attribution resource="text"> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </attribution> + <copyright resource="original"> + <owner> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </owner> + </copyright> + <copyright resource="digital-image"> + <owner> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </owner> + <license type="cc-by-sa"/> + </copyright> + <copyright resource="text"> + <owner> + <name>Max Planck Institute for the History of Science, Library</name> + <url>http://www.mpiwg-berlin.mpg.de/</url> + </owner> + <license type="cc-by-sa"/> + </copyright> + </access-conditions> + <texttool> + <image>pageimg</image> + <figures>figures</figures> + <text-url-path>/echo/la/Apian_1550_PUBSU9QD.xml</text-url-path> + <title-scan-no>3</title-scan-no> + </texttool> + <dri type="mpiwg">MPIWG:WBGMR64C</dri> + </meta> + </resource>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,66 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <groupId>de.mpiwg.indexmeta</groupId> + <artifactId>indexmeta</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>de.mpiwg.indexmeta</name> + + <build> + <directory>target</directory> + <sourceDirectory>src/main/java</sourceDirectory> + + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <includes> + <include>resources</include> + </includes> + </configuration> + </plugin> + </plugins> + + </build> + + <dependencies> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>3.5.5-Final</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.0.4</version> + </dependency> + <dependency> + <groupId>c3p0</groupId> + <artifactId>c3p0</artifactId> + <version>0.9.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.6.6</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.6.6</version> + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.13</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + + </dependencies> + +</project> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/META-INF/persistence.xml Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,38 @@ +<!-- +<persistence xmlns="http://java.sun.com/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" + version="1.0"> + + <persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL"> + <provider>org.hibernate.ejb.HibernatePersistence</provider> + <class>de.mpiwg.indexmeta.bo.Message</class> + + <properties> + <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test" /> + <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> + <property name="hibernate.connection.username" value="root" /> + <property name="hibernate.connection.password" value="admin" /> + + </properties> + + </persistence-unit> +</persistence> + --> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> + <persistence-unit name="uno" transaction-type="RESOURCE_LOCAL"> + <provider>org.hibernate.ejb.HibernatePersistence</provider> + <class>de.mpiwg.indexmeta.bo.Contextualization</class> + <properties> + <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/> + <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> + <property name="hibernate.show_sql" value="true"/> + <property name="hibernate.connection.username" value="root"/> + <property name="hibernate.connection.password" value="admin"/> + <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test"/> + <property name="hibernate.max_fetch_depth" value="3"/> + <property name="hibernate.hbm2ddl.auto" value="create" /> + </properties> + </persistence-unit> +</persistence> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/AnnotateIndexMeta.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,94 @@ +package de.mpiwg.indexmeta; +// import stuff +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import javax.print.attribute.standard.MediaSize.Other; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class AnnotateIndexMeta { + + public static void main(String argv[]) { + System.out.println("in main"); + + // Methodenaufruf + String filepath = "/Users/kthoden/eclipse/workspace/dm2eStuff/data/index.meta"; + // this is a list of all the elements we want to contextualize + List<String> contextualizableList = Arrays.asList(new String[]{"author","editor","publisher","city","holding-library","keywords"}); + xmlParse(filepath,contextualizableList); + System.out.println("Done"); + } + + /** + * Parses the XML file given as first argument and writes attributes in elements that are to be contextualized. + * @param filepath path to the file. It will also be used as the basis for the output file (this adds "-annot"). + * @param contextualizableList contains the elements that shall be given a context identifier which is later used to grab the contents and put them into the database to have it contextualized. + * + */ + public static void xmlParse(String filepath, List<String> contextualizableList) { + try { + // this is how the outputfile will be called + String outfilepath = filepath + "-annot"; + // open the file and parse it + DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + Document doc = docBuilder.parse(filepath); + + // iterate through the document + Integer count = 0; + for(String contextElement : contextualizableList){ + NodeList nodeList = doc.getElementsByTagName(contextElement); + for(int i=0; i < nodeList.getLength(); i++){ + Node iter2 = nodeList.item(i); + NamedNodeMap attr = iter2.getAttributes(); + // make a new attribute + // DONE would be good if it left existing outputs alone + if (attr.getNamedItem("context-id") == null){ + Attr attribute = doc.createAttribute ("context-id"); + attribute.setValue (count.toString()); + attr.setNamedItem (attribute); + } + else { + System.out.println("schon da: " + attr.getNamedItem("context-id")); + } + // Just for comfort. Print it out. + System.out.println(contextElement); + count++; + } + // get the element by name (so they should be unique?) + //Node iter2 = doc.getElementsByTagName(contextElement).item(0); + } + // write the content into xml file + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(doc); + StreamResult result = new StreamResult(new File(outfilepath)); + transformer.transform(source, result); + + } catch (ParserConfigurationException pce) { + pce.printStackTrace(); + } catch (TransformerException tfe) { + tfe.printStackTrace(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } catch (SAXException sae) { + sae.printStackTrace(); + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/DataProvider.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,36 @@ +package de.mpiwg.indexmeta; + +import java.util.ArrayList; +import java.util.List; + +import de.mpiwg.indexmeta.bo.Contextualization; +import de.mpiwg.indexmeta.utils.QuadKey; + +public class DataProvider { + + private PersistentService ps = new PersistentService(); + + public List<Contextualization> getCtxByIndexMetaId(String indexMetaId){ + //QuadKey(indexMetaId, elementId, remoteId, id) + return ps.getCtxMap().getValuesByFirstKey(indexMetaId); + } + + public List<Contextualization> getCtxByElementId(String elementId){ + //QuadKey(indexMetaId, elementId, remoteId, id) + return ps.getCtxMap().getValuesBySecondKey(elementId); + } + + public List<Contextualization> getCtxByRemoteId(String remoteId){ + //QuadKey(indexMetaId, elementId, remoteId, id) + return ps.getCtxMap().getValuesByThirdKey(remoteId); + } + + public Contextualization getCtx(Long id){ + return ps.getCtxMap().getValuesByOwnKey(id); + } + + public void saveCtx(Contextualization ctx){ + ps.saveCtx(ctx); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/IndexMetaParser.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,127 @@ +package de.mpiwg.indexmeta; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import de.mpiwg.indexmeta.bo.Contextualization; + +public class IndexMetaParser { + + + public static List<Contextualization> getCtxItems(String filePath){ + List<Contextualization> rs = new ArrayList<Contextualization>(); + + try { + File file = new File("/Users/jurzua/Projects/workspace/contextualization/data/index.meta/01index.meta.anno.xml"); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(file); + + List<Node> nodes = getNodeList(doc, Contextualization.AUTHOR); + for(Node node : nodes){ + Contextualization ctx = getCtx(node, "XX"); + if(ctx != null){ + rs.add(ctx); + } + } + + nodes = getNodeList(doc, Contextualization.CITY); + for(Node node : nodes){ + Contextualization ctx = getCtx(node, "XX"); + if(ctx != null){ + rs.add(ctx); + } + } + + for(Contextualization ctx : rs){ + System.out.println(ctx.toString()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return rs; + } + + public static List<Node> getNodeList(Document doc, String tagName){ + List<Node> rs = new ArrayList<Node>(); + + try { + XPathFactory xPathfactory = XPathFactory.newInstance(); + XPath xpath = xPathfactory.newXPath(); + XPathExpression expr = xpath.compile("//" + tagName); + + Object result = expr.evaluate(doc, XPathConstants.NODESET); + + NodeList nodes = (NodeList) result; + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + rs.add(node); + } + } catch (Exception e) { + e.printStackTrace(); + } + + return rs; + + } + + public static Contextualization getCtx(Node node, String indexMetaId){ + if(node instanceof Element){ + try{ + Element elem = (Element)node; + Contextualization ctx = new Contextualization(); + ctx.setIndexMetaId(indexMetaId); + ctx.setType(elem.getNodeName()); + ctx.setElementId(elem.getAttribute("context-id")); + + Node child = elem.getFirstChild(); + if(child != null){ + ctx.setContent(child.getNodeValue()); + } + return ctx; + }catch (Exception e) { + e.printStackTrace(); + } + } + + + return null; + } + + public static void main(String[] args){ + + getCtxItems("/Users/jurzua/Projects/workspace/contextualization/data/index.meta/01index.meta"); + } + + public static void printXpathResult(Object result){ + NodeList nodes = (NodeList) result; + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if(node instanceof Element){ + Element e = (Element)node; + + System.out.println("Local Name= " + node.getLocalName()); + System.out.println("Value= " + node.getNodeValue()); + System.out.println("Name= " + node.getNodeName()); + System.out.println("getFirstChild value= " + node.getFirstChild().getNodeValue()); + System.out.println(node); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/PersistentService.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,71 @@ +package de.mpiwg.indexmeta; + +import java.util.List; + +import javax.persistence.Query; + +import de.mpiwg.indexmeta.bo.Contextualization; +import de.mpiwg.indexmeta.utils.QuadMap; + +public class PersistentService { + + private QuadMap<Contextualization> ctxMap = null; + private javax.persistence.EntityManagerFactory emf; + private javax.persistence.EntityManager em; + private String PERSISTENCE_UNIT_NAME = "uno"; + + + public QuadMap<Contextualization> getCtxMap() { + if(ctxMap == null){ + this.loadCtxMap(); + } + return ctxMap; + } + + public void saveCtx(Contextualization ctx){ + System.out.println("Saving= " + ctx.toString()); + + initEntityManager(); + em.getTransaction().begin(); + + em.persist(ctx); + ctxMap.put(ctx.getKey(), ctx); + + em.getTransaction().commit(); + closeEntityManager(); + + System.out.println("Saved= " + ctx.toString()); + } + + + private void loadCtxMap(){ + ctxMap = new QuadMap<Contextualization>(); + + initEntityManager(); + em.getTransaction().begin(); + + Query q = em.createQuery("from Contextualization"); + List<Contextualization> list = q.getResultList(); + + for(Contextualization ctx : list){ + ctxMap.put(ctx.getKey(), ctx); + } + + em.getTransaction().commit(); + closeEntityManager(); + } + + + private void initEntityManager() { + emf = javax.persistence.Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); + em = emf.createEntityManager(); + } + + private void closeEntityManager() { + em.close(); + emf.close(); + } + + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/bo/Contextualization.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,104 @@ + package de.mpiwg.indexmeta.bo; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import de.mpiwg.indexmeta.utils.QuadKey; + +@Entity +public class Contextualization { + + @Id + @GeneratedValue + private Long id; + + private String indexMetaId; + private String elementId; + private String xpath; + private String remoteId; + private String state; + private String comment; + private String content; + + public static String PUBLISHER = "publisher"; + public static String CITY = "city"; + public static String HOLDING_LIBRARY = "holding-library"; + public static String AUTHOR = "author"; + + //"publisher","city","holding-library", "author" + private String type; + + public String getIndexMetaId() { + return indexMetaId; + } + public void setIndexMetaId(String indexMetaId) { + this.indexMetaId = indexMetaId; + } + public String getElementId() { + return elementId; + } + public void setElementId(String elementId) { + this.elementId = elementId; + } + public String getXpath() { + return xpath; + } + public void setXpath(String xpath) { + this.xpath = xpath; + } + public String getRemoteId() { + return remoteId; + } + public void setRemoteId(String remoteId) { + this.remoteId = remoteId; + } + public String getState() { + return state; + } + public void setState(String state) { + this.state = state; + } + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getContent() { + return content; + } + public void setContent(String content) { + this.content = content; + } + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + public QuadKey<String, String, String> getKey(){ + return new QuadKey<String, String, String>(indexMetaId, elementId, remoteId, id); + } + + @Override + public String toString(){ + StringBuilder sb = new StringBuilder("Ctx ["); + + sb.append("indexMetaId=" + indexMetaId); + sb.append(", type=" + type); + sb.append(", elementId=" + elementId); + sb.append(", remoteId=" + remoteId); + sb.append(", content=" + content); + + sb.append("]"); + return sb.toString(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/utils/IQuadMap.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,51 @@ +package de.mpiwg.indexmeta.utils; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +public interface IQuadMap<V> { + + int size(); + + boolean isEmpty(); + + boolean containsKey(QuadKey key); + + boolean containsValue(Object value); + + V get(QuadKey key); + + V put(QuadKey key, V value); + + V remove(QuadKey key); + + //void putAll(Map<? extends K, ? extends V> m); + + void clear(); + + Set<QuadKey> keySet(); + + Collection<V> values(); + + Set<Map.Entry<QuadKey, V>> entrySet(); + + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is + * defined to be the sum of the hash codes of each entry in the map's + * <tt>entrySet()</tt> view. This ensures that <tt>m1.equals(m2)</tt> + * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps + * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of + * {@link Object#hashCode}. + * + * @return the hash code value for this map + * @see Map.Entry#hashCode() + * @see Object#equals(Object) + * @see #equals(Object) + */ + int hashCode(); + + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/utils/QuadKey.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,116 @@ +package de.mpiwg.indexmeta.utils; + +public class QuadKey<F, S, T> { + private F firstKey; + private S secondKey; + private T thirdKey; + private Object ownKey; + /* + public QuadKey(Long firstKey, Long secondKey, Long thirdKey, Long ownKey){ + this.firstKey = firstKey; + this.secondKey = secondKey; + this.thirdKey = thirdKey; + this.ownKey = ownKey; + }*/ + + public QuadKey(F firstKey, S secondKey, T thirdKey, Long ownKey){ + this.firstKey = firstKey; + this.secondKey = secondKey; + this.thirdKey = thirdKey; + this.ownKey = ownKey; + } + + /* + public boolean containsKey(Object key){ + if(key != null){ + if(key.equals(firstKey) || key.equals(secondKey) || key.equals(ownKey)){ + return true; + } + } + return false; + }*/ + + + public boolean equalsFirstKey(Object key){ + if(firstKey != null && key != null){ + return firstKey.equals(key); + }else if(firstKey == null && key == null){ + return true; + } + return false; + } + + public boolean equalsSecondKey(Object key){ + if(secondKey != null && key != null){ + return secondKey.equals(key); + }else if(secondKey == null && key == null){ + return true; + } + return false; + } + + public boolean equalsThirdKey(Object key){ + if(thirdKey != null && key != null){ + return thirdKey.equals(key); + }else if(thirdKey == null && key == null){ + return true; + } + return false; + } + + public boolean equalsOwnKey(Object key){ + if(ownKey != null && key != null){ + return ownKey.equals(key); + }else if(ownKey == null && key == null){ + return true; + } + return false; + } + + public Object getFirstKey() { + return firstKey; + } + + public void setFirstKey(F firstKey) { + this.firstKey = firstKey; + } + + public Object getSecondKey() { + return secondKey; + } + + public void setSecondKey(S secondKey) { + this.secondKey = secondKey; + } + + public Object getOwnKey() { + return ownKey; + } + + public void setOwnKey(Object ownKey) { + this.ownKey = ownKey; + } + + public Object getThirdKey() { + return thirdKey; + } + + public void setThirdKey(T thirdKey) { + this.thirdKey = thirdKey; + } + + @Override + public boolean equals(Object o){ + if(o instanceof QuadKey){ + QuadKey other = (QuadKey)o; + + if(this.equalsOwnKey(other.getOwnKey()) && + this.equalsFirstKey(other.getFirstKey()) && + this.equalsSecondKey(other.getSecondKey()) && + this.equalsThirdKey(other.getThirdKey())){ + return true; + } + } + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/utils/QuadMap.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,191 @@ +package de.mpiwg.indexmeta.utils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class QuadMap<V> implements IQuadMap<V>{ + + private Map<QuadKey, V> map; + private Map<Object, List<QuadKey>> mapFirstKey; + private Map<Object, List<QuadKey>> mapSecondKey; + private Map<Object, List<QuadKey>> mapThirdKey; + private Map<Object, QuadKey> mapOwnKey; + + public QuadMap(){ + this.map = new HashMap<QuadKey, V>(); + this.mapFirstKey = new HashMap<Object, List<QuadKey>>(); + this.mapSecondKey = new HashMap<Object, List<QuadKey>>(); + this.mapThirdKey = new HashMap<Object, List<QuadKey>>(); + this.mapOwnKey = new HashMap<Object, QuadKey>(); + } + + public QuadMap(QuadMap<? extends V> m) { + this.map = new HashMap<QuadKey, V>(); + this.mapFirstKey = new HashMap<Object, List<QuadKey>>(); + this.mapSecondKey = new HashMap<Object, List<QuadKey>>(); + this.mapThirdKey = new HashMap<Object, List<QuadKey>>(); + this.mapOwnKey = new HashMap<Object, QuadKey>(); + this.putAllForCreate(m); + } + + private void putAllForCreate(QuadMap<? extends V> m) { + for(Map.Entry<QuadKey, ? extends V> e : m.entrySet()){ + QuadKey tKey = e.getKey(); + this.map.put(tKey, e.getValue()); + this.mapOwnKey.put(tKey.getOwnKey(), tKey); + + if(!mapFirstKey.containsKey(tKey.getFirstKey())){ + mapFirstKey.put(tKey.getFirstKey(), new ArrayList<QuadKey>()); + } + if(!mapFirstKey.get(tKey.getFirstKey()).contains(tKey)){ + mapFirstKey.get(tKey.getFirstKey()).add(tKey); + } + + if(!mapSecondKey.containsKey(tKey.getSecondKey())){ + mapSecondKey.put(tKey.getSecondKey(), new ArrayList<QuadKey>()); + } + if(!mapSecondKey.get(tKey.getSecondKey()).contains(tKey)){ + mapSecondKey.get(tKey.getSecondKey()).add(tKey); + } + + if(!mapThirdKey.containsKey(tKey.getThirdKey())){ + mapThirdKey.put(tKey.getThirdKey(), new ArrayList<QuadKey>()); + } + if(!mapThirdKey.get(tKey.getThirdKey()).contains(tKey)){ + mapThirdKey.get(tKey.getThirdKey()).add(tKey); + } + } + } + + public List<V> getValuesByFirstKey(Object srcKey){ + List<V> list = new ArrayList<V>(); + if(mapFirstKey.containsKey(srcKey)){ + for(QuadKey tKey : mapFirstKey.get(srcKey)){ + list.add(map.get(tKey)); + } + } + return list; + } + + public List<V> getValuesBySecondKey(Object tarKey){ + List<V> list = new ArrayList<V>(); + if(mapSecondKey.containsKey(tarKey)){ + for(QuadKey tKey : mapSecondKey.get(tarKey)){ + list.add(map.get(tKey)); + } + } + return list; + } + + public List<V> getValuesByThirdKey(Object thirdKey){ + List<V> list = new ArrayList<V>(); + if(mapThirdKey.containsKey(thirdKey)){ + for(QuadKey tKey : mapThirdKey.get(thirdKey)){ + list.add(map.get(tKey)); + } + } + return list; + } + + public V getValuesByOwnKey(Object ownKey){ + QuadKey tKey = mapOwnKey.get(ownKey); + if(tKey != null){ + return this.map.get(tKey); + } + return null; + } + + public Set<QuadKey> keySet(){ + return this.map.keySet(); + } + + public Set<Map.Entry<QuadKey, V>> entrySet() { + return this.map.entrySet(); + } + + @Override + public int size() { + return this.map.size(); + } + + @Override + public boolean isEmpty() { + return this.map.isEmpty(); + } + + @Override + public boolean containsKey(QuadKey key) { + return this.map.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return this.map.containsValue(value); + } + + @Override + public V get(QuadKey key) { + return map.get(key); + } + + @Override + public V put(QuadKey tKey, V value) { + + if(!mapFirstKey.containsKey(tKey.getFirstKey())){ + mapFirstKey.put(tKey.getFirstKey(), new ArrayList<QuadKey>()); + } + if(!mapFirstKey.get(tKey.getFirstKey()).contains(tKey)){ + mapFirstKey.get(tKey.getFirstKey()).add(tKey); + } + + if(!mapSecondKey.containsKey(tKey.getSecondKey())){ + mapSecondKey.put(tKey.getSecondKey(), new ArrayList<QuadKey>()); + } + if(!mapSecondKey.get(tKey.getSecondKey()).contains(tKey)){ + mapSecondKey.get(tKey.getSecondKey()).add(tKey); + } + + if(!mapThirdKey.containsKey(tKey.getThirdKey())){ + mapThirdKey.put(tKey.getThirdKey(), new ArrayList<QuadKey>()); + } + if(!mapThirdKey.get(tKey.getThirdKey()).contains(tKey)){ + mapThirdKey.get(tKey.getThirdKey()).add(tKey); + } + + this.mapOwnKey.put(tKey.getOwnKey(), tKey); + return this.map.put(tKey, value); + } + + @Override + public V remove(QuadKey key) { + if(mapFirstKey.containsKey(key.getFirstKey())){ + mapFirstKey.get(key.getFirstKey()).remove(key); + } + if(mapSecondKey.containsKey(key.getSecondKey())){ + mapSecondKey.get(key.getSecondKey()).remove(key); + } + if(mapThirdKey.containsKey(key.getThirdKey())){ + mapThirdKey.get(key.getThirdKey()).remove(key); + } + this.mapOwnKey.remove(key.getOwnKey()); + return this.map.remove(key); + } + + @Override + public void clear() { + this.map.clear(); + this.mapFirstKey.clear(); + this.mapSecondKey.clear(); + this.mapThirdKey.clear(); + this.mapOwnKey.clear(); + } + + @Override + public Collection<V> values() { + return this.map.values(); + } +}