Mercurial > hg > IndexMetaContextualizer
comparison src/main/java/de/mpiwg/indexmeta/AnnotateIndexMeta.java @ 8:9ce7979fd037
Implementation Data Provider
author | Jorge Urzua <jurzua@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 24 Apr 2013 10:34:23 +0200 |
parents | bc57f2660b0f |
children |
comparison
equal
deleted
inserted
replaced
7:bc57f2660b0f | 8:9ce7979fd037 |
---|---|
21 import org.w3c.dom.NamedNodeMap; | 21 import org.w3c.dom.NamedNodeMap; |
22 import org.w3c.dom.Node; | 22 import org.w3c.dom.Node; |
23 import org.w3c.dom.NodeList; | 23 import org.w3c.dom.NodeList; |
24 import org.xml.sax.SAXException; | 24 import org.xml.sax.SAXException; |
25 | 25 |
26 import de.mpiwg.indexmeta.bo.Contextualization; | |
27 import de.mpiwg.indexmeta.services.DataProvider; | |
28 | |
26 public class AnnotateIndexMeta { | 29 public class AnnotateIndexMeta { |
27 | 30 |
28 public static void main(String argv[]) { | 31 public static void main(String argv[]) { |
29 System.out.println("in main"); | 32 System.out.println("in main"); |
30 | 33 |
31 // Methodenaufruf | 34 // Methodenaufruf |
32 String filepath = "/Users/kthoden/eclipse/workspace/IndexMetaContextualization/data/index.meta/index.meta_FQPFR8XP"; | 35 String filepath = "/Users/kthoden/eclipse/workspace/IndexMetaContextualization/data/index.meta/index.meta_FQPFR8XP"; |
33 // this is a list of all the elements we want to contextualize | 36 // this is a list of all the elements we want to contextualize |
34 List<String> contextualizableList = Arrays.asList(new String[]{"author","editor","publisher","city","holding-library","keywords"}); | 37 //List<String> contextualizableList = Arrays.asList(new String[]{"author","editor","publisher","city","holding-library","keywords"}); |
35 try {xmlParse(filepath,contextualizableList); | 38 try { |
39 | |
40 DataProvider dp = new DataProvider(); | |
41 xmlParse(filepath, dp); | |
36 } | 42 } |
37 catch (Exception e) { | 43 catch (Exception e) { |
38 e.printStackTrace(); | 44 e.printStackTrace(); |
39 }; | 45 }; |
40 System.out.println("Done"); | 46 System.out.println("Done"); |
45 * @param filepath path to the file. It will also be used as the basis for the output file (this adds "-annot"). | 51 * @param filepath path to the file. It will also be used as the basis for the output file (this adds "-annot"). |
46 * @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. | 52 * @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. |
47 * @throws Exception which means that in the source index.meta file there are already markers for contextualization. | 53 * @throws Exception which means that in the source index.meta file there are already markers for contextualization. |
48 * | 54 * |
49 */ | 55 */ |
50 public static void xmlParse(String filepath, List<String> contextualizableList) throws Exception { | 56 public static File xmlParse(String filepath, DataProvider dp) throws Exception { |
57 /* | |
58 Contextualization ctx = new Contextualization(); | |
59 ctx.setElementId("context-id value"); | |
60 ctx.setIndexMetaId("ABABABA"); | |
61 ctx.setContent("KLaus"); | |
62 ctx.setType(Contextualization.AUTHOR); | |
63 ctx.setRemoteId(""); | |
64 dp.saveCtx(ctx); | |
65 */ | |
66 File file = null; | |
51 try { | 67 try { |
52 // this is how the outputfile will be called | 68 // this is how the outputfile will be called |
53 String outfilepath = filepath + "-annot"; | 69 String outfilepath = filepath + ".annot"; |
54 // open the file and parse it | 70 // open the file and parse it |
55 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); | 71 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); |
56 DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); | 72 DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); |
57 Document doc = docBuilder.parse(filepath); | 73 Document doc = docBuilder.parse(filepath); |
58 | 74 |
59 // iterate through the document | 75 // iterate through the document |
60 Integer count = 0; | 76 Integer count = 0; |
61 for(String contextElement : contextualizableList){ | 77 for(String contextElement : Contextualization.contextualizableList){ |
62 NodeList nodeList = doc.getElementsByTagName(contextElement); | 78 NodeList nodeList = doc.getElementsByTagName(contextElement); |
63 for(int i=0; i < nodeList.getLength(); i++){ | 79 for(int i=0; i < nodeList.getLength(); i++){ |
64 Node iter2 = nodeList.item(i); | 80 Node iter2 = nodeList.item(i); |
65 String currentNodeValue = null; | 81 String currentNodeValue = null; |
66 //String currentNodeValue = iter2.getTextContent(); | 82 //String currentNodeValue = iter2.getTextContent(); |
85 } | 101 } |
86 // write the content into xml file | 102 // write the content into xml file |
87 TransformerFactory transformerFactory = TransformerFactory.newInstance(); | 103 TransformerFactory transformerFactory = TransformerFactory.newInstance(); |
88 Transformer transformer = transformerFactory.newTransformer(); | 104 Transformer transformer = transformerFactory.newTransformer(); |
89 DOMSource source = new DOMSource(doc); | 105 DOMSource source = new DOMSource(doc); |
90 StreamResult result = new StreamResult(new File(outfilepath)); | 106 file = new File(outfilepath); |
107 StreamResult result = new StreamResult(file); | |
91 transformer.transform(source, result); | 108 transformer.transform(source, result); |
92 /* | 109 /* |
93 * should these really go inside this method? | 110 * should these really go inside this method? |
94 */ | 111 */ |
95 } catch (ParserConfigurationException pce) { | 112 } catch (ParserConfigurationException pce) { |
99 } catch (IOException ioe) { | 116 } catch (IOException ioe) { |
100 ioe.printStackTrace(); | 117 ioe.printStackTrace(); |
101 } catch (SAXException sae) { | 118 } catch (SAXException sae) { |
102 sae.printStackTrace(); | 119 sae.printStackTrace(); |
103 } | 120 } |
121 return file; | |
104 } | 122 } |
105 | 123 |
106 /** | 124 /** |
107 * this method checks the current index.meta file for already existing contextualizations. For example, newer generations of index.meta (as of 2013) already do have GND information for persons associated with the object in question. | 125 * this method checks the current index.meta file for already existing contextualizations. For example, newer generations of index.meta (as of 2013) already do have GND information for persons associated with the object in question. |
108 * However, for the sake of backwards compatibility, the nearly-deprecated "author" element is also existant (as well as "city", which is meant to be replaced by "place" which in turn might be superseded by "geo-location") | 126 * However, for the sake of backwards compatibility, the nearly-deprecated "author" element is also existant (as well as "city", which is meant to be replaced by "place" which in turn might be superseded by "geo-location") |