/* * AnchorWordList.java * * ... * ... * ... */ package aksis.alignment; // ¤¤¤ ikke sjekket nøyaktig hva vi trenger import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.lang.String; import java.io.*; //import aksis.awt2.AwtUtil; /** * entry in anchor word list. * array with one element for each language. * each language element is a list of arrays. * each array contains a phrase with one word per element. * most phrases will have just one word */ class AnchorWordListEntry { // for hvert språk en liste av "synonymer" java.util.List[] language = new ArrayList[Alignment.NUM_FILES]; // ¤¤¤ skal vel heller være 2 public AnchorWordListEntry(String anchorWordListEntryText) throws Exception { // anchorWordListEntryText syntax must be e.g "en,et/one" with delimiters "/" and "'" and no whitespace whatsoever //System.out.println("anchorWordListEntryText.length()=" + anchorWordListEntryText.length()); //System.out.println("anchorWordListEntryText=" + anchorWordListEntryText); String[] temp = new String[Alignment.NUM_FILES]; if (anchorWordListEntryText.length() > 0) { //System.out.println("splitter entry"); String[] data = anchorWordListEntryText.split("/"); // split entry into array of data for each text/language //System.out.println("har splittet entry"); if (data.length < Alignment.NUM_FILES) { throw new Exception("No slash: " + anchorWordListEntryText); // §§§ } else if (data.length > Alignment.NUM_FILES) { throw new Exception("Too many slashes: " + anchorWordListEntryText); // §§§ } for (int t=0; t phrase = new ArrayList(); // array to contain one phrase, with one word per element for (int w=0; w 0) { //System.out.println("legger til frase i data-liste"); language[t].add(phrase); //System.out.println("har lagt til frase i data-liste"); } //System.out.println("ferdig med en frase"); } //System.out.println("ferdig med data for et språk"); } //System.out.println("ferdig med hele entry"); } } } /** * anchor word list. * list, with each element a AnchorWordListEntry. */ class AnchorWordList { java.util.List entries = new ArrayList(); // explicit to avoid ambiguousness AlignmentModel model; //AnchorWordList() { // // ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ foreløpig hardkodet ¤ // entries.add(new AnchorWordListEntry("paragraph/avsnittet")); // entries.add(new AnchorWordListEntry("inflation/inflasjon,inflasjonen")); // entries.add(new AnchorWordListEntry("policy/pengepolitikken")); // entries.add(new AnchorWordListEntry("krone/krone,kronen,kronens,kroner")); // entries.add(new AnchorWordListEntry("euro/euro")); //} AnchorWordList(AlignmentModel model) { this.model = model; } /* * Added by boerre */ public void loadFromFile(File fromFile) { entries.clear(); boolean ok = true; try { BufferedReader in = new BufferedReader(new FileReader(fromFile)); String str; while ((str = in.readLine()) != null) { try { entries.add(new AnchorWordListEntry(str.trim())); } catch (Exception e) { System.err.println("Error in anchor word entry: " + e.getMessage()); ok = false; break; } } } catch (IOException e) { } if (!ok) { System.out.println("Error occurred. clear list again"); entries.clear(); // ¤¤¤ er ikke dette bedre? } } public void load(ArrayList lines) { //System.out.println("AnchorWordList sin load()"); //System.out.println("lines.size() = " + lines.size()); // clear list //java.util.List entries = new ArrayList(); denne førte til at model sin anchorWordList likevel ikke ble satt. har ikke tenkt gjennom hvorfor entries.clear(); // load list boolean ok = true; Iterator it = lines.iterator(); while (it.hasNext()) { String line = ((String)(it.next())).trim(); if (line.length() > 0) { //System.out.println("line='"+line+"'"); try { entries.add(new AnchorWordListEntry(line)); } catch (Exception e) { System.err.println("Error in anchor word entry: " + e.getMessage()); JOptionPane.showMessageDialog( null, "Error in anchor word entry: " + e.getMessage(), "Error in anchor word entry", JOptionPane.ERROR_MESSAGE ); ok = false; break; } } //System.out.println("entries.size() = " + entries.size()); } if (!ok) { // error occurred. clear list again System.out.println("Error occurred. clear list again"); //entries = new ArrayList(); entries.clear(); // ¤¤¤ er ikke dette bedre? } } public void display(JTextArea content) { if (entries != null) { Iterator eIt = entries.iterator(); while (eIt.hasNext()) { //System.out.println("neste entry"); StringBuffer anchorWordListEntryText = new StringBuffer(""); AnchorWordListEntry anchorWordListEntry = (AnchorWordListEntry)eIt.next(); for (int t=0; t>>>>>>>>>>getAnchorWordHits<<<<<<<<<<<<"); AnchorWordHits ret = new AnchorWordHits(); // Iterator aIt = this.entries.iterator(); int anchorWordEntryCount = 0; while (aIt.hasNext()) { //System.out.println("anchorWordEntryCount = " + anchorWordEntryCount); //java.util.List synonyms = ((AnchorWordListEntry)(aIt.next())).language[t]; AnchorWordListEntry entry = (AnchorWordListEntry)(aIt.next()); java.util.List synonyms = (java.util.List)(entry.language[t]); Iterator sIt = synonyms.iterator(); while (sIt.hasNext()) { java.util.List anchorPhrase = (java.util.List)sIt.next(); //System.out.println("anchorPhrase = " + anchorPhrase); for (int w=0; w