comparison src/main/java/de/mpiwg/indexmeta/AnnotateIndexMeta.java @ 6:7a2a98655236

Some more changes. Class is now in a stable state.
author Klaus Thoden <kthoden@mpiwg-berlin.mpg.de>
date Fri, 12 Apr 2013 17:48:10 +0200
parents 8f6c4dab5d17
children
comparison
equal deleted inserted replaced
5:7d231e4e86e5 6:7a2a98655236
27 27
28 public static void main(String argv[]) { 28 public static void main(String argv[]) {
29 System.out.println("in main"); 29 System.out.println("in main");
30 30
31 // Methodenaufruf 31 // Methodenaufruf
32 String filepath = "/Users/kthoden/eclipse/workspace/IndexMetaContextualization/data/index.meta/index.meta_FQPFR8XP"; 32 String filepath = "/Users/kthoden/eclipse/workspace/IndexMetaContextualizer/data/index.meta/index.meta_FQPFR8XP";
33 // this is a list of all the elements we want to contextualize 33 // 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"}); 34 List<String> contextualizableList = Arrays.asList(new String[]{"author","editor","publisher","city","holding-library","keywords"});
35 try {xmlParse(filepath,contextualizableList); 35 try {xmlParse(filepath,contextualizableList);
36 } 36 }
37 catch (Exception e) { 37 catch (Exception e) {
60 Integer count = 0; 60 Integer count = 0;
61 for(String contextElement : contextualizableList){ 61 for(String contextElement : contextualizableList){
62 NodeList nodeList = doc.getElementsByTagName(contextElement); 62 NodeList nodeList = doc.getElementsByTagName(contextElement);
63 for(int i=0; i < nodeList.getLength(); i++){ 63 for(int i=0; i < nodeList.getLength(); i++){
64 Node iter2 = nodeList.item(i); 64 Node iter2 = nodeList.item(i);
65 String currentNodeValue = iter2.getTextContent(); 65 String currentNodeValue = iter2.getFirstChild().getNodeValue();
66 NamedNodeMap attr = iter2.getAttributes(); 66 NamedNodeMap attr = iter2.getAttributes();
67 // make a new attribute 67 // make a new attribute
68 if (attr.getNamedItem("context-id") == null){ 68 if (attr.getNamedItem("context-id") == null){
69 Attr attribute = doc.createAttribute ("context-id"); 69 Attr attribute = doc.createAttribute ("context-id");
70 attribute.setValue (count.toString()); 70 attribute.setValue (count.toString());
72 } 72 }
73 else {throw new Exception("There is already at least one context-id attribute in the source index.meta. This is not allowed. "); 73 else {throw new Exception("There is already at least one context-id attribute in the source index.meta. This is not allowed. ");
74 } 74 }
75 // Just for comfort. Print it out. 75 // Just for comfort. Print it out.
76 System.out.println(contextElement); 76 System.out.println(contextElement);
77 if (contextElement == "author") { 77 if (contextElement == "author" || contextElement == "editor") {
78 findContext(doc, currentNodeValue); 78 checkExistingContext(doc, currentNodeValue);
79 } 79 }
80 count++; 80 count++;
81 } 81 }
82 // get the element by name (so they should be unique?) 82 // get the element by name (so they should be unique?)
83 //Node iter2 = doc.getElementsByTagName(contextElement).item(0); 83 //Node iter2 = doc.getElementsByTagName(contextElement).item(0);
107 * 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") 107 * 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")
108 * Technically, we parse the XML and construct a map containing a persons name, its remote ID and its role. 108 * Technically, we parse the XML and construct a map containing a persons name, its remote ID and its role.
109 * @param doc 109 * @param doc
110 * @param currentNodeValue 110 * @param currentNodeValue
111 */ 111 */
112 public static void findContext(Document doc, String currentNodeValue) { 112 public static void checkExistingContext(Document doc, String currentNodeValue) {
113 // first, define some variables 113 // first, define some variables
114 String nameOfPerson = ""; 114 String nameOfPerson = "";
115 String roleOfPerson = ""; 115 String roleOfPerson = "";
116 String idOfPerson= ""; 116 String idOfPerson= "";
117 117
119 // let us concentrate on that element 119 // let us concentrate on that element
120 // then we look for tags called person 120 // then we look for tags called person
121 // if there are any, we take the liberty of querying them. This is a Nodelist 121 // if there are any, we take the liberty of querying them. This is a Nodelist
122 NodeList personList = doc.getElementsByTagName("person"); 122 NodeList personList = doc.getElementsByTagName("person");
123 // Debug information for the human eye. 123 // Debug information for the human eye.
124 // System.out.println("The current node value is "+ currentNodeValue + ". Let's do something useful in the findContext method."); 124 // System.out.println("The current node value is "+ currentNodeValue + ". Let's do something useful in the checkExistingContext method.");
125 // System.out.println("This node list has " + personList.getLength() + " members: " + personList.item(0) + "and" + personList.item(1)); 125 // System.out.println("This node list has " + personList.getLength() + " members: " + personList.item(0) + "and" + personList.item(1));
126 // Integer personCounter = 1; 126 // Integer personCounter = 1;
127 // look at every element in the list of persons 127 // look at every element in the list of persons
128 for(int countPerson=0; countPerson < personList.getLength(); countPerson++){ 128 for(int countPerson=0; countPerson < personList.getLength(); countPerson++){
129 // just some control 129 // just some control
162 162
163 System.out.println("This person has already been contextualized: " + nameOfPerson + " hat die Rolle " + roleOfPerson + " und den Identifier " + idOfPerson + "."); 163 System.out.println("This person has already been contextualized: " + nameOfPerson + " hat die Rolle " + roleOfPerson + " und den Identifier " + idOfPerson + ".");
164 }} 164 }}
165 // personCounter ++; 165 // personCounter ++;
166 } 166 }
167 System.out.println("printing author");
168 } 167 }
169 } 168 }
170 169