Esempio n. 1
0
 /**
  * Construct new Event set (with empty vector) of known author
  *
  * @param Author the name of the author
  */
 public EventSet(String Author) {
   events = new ArrayList<Event>();
   setAuthor(Author);
   setNewEventSetID(Author);
 }
Esempio n. 2
0
 /**
  * Creates a empty list of event of the specified size
  *
  * @param size
  */
 public EventSet(int size) {
   events = new ArrayList<Event>(size);
   setAuthor("default");
   setNewEventSetID("default");
 }
Esempio n. 3
0
 /** Creates a new list of events given a previously created list of events * */
 public EventSet(List<Event> evts) {
   events = new ArrayList<Event>(evts);
   setAuthor("default");
   setNewEventSetID("default");
 }
Esempio n. 4
0
  @Override
  public EventSet createEventSet(Document ds) throws EventGenerationException {
    String param;
    HashMap<String, String> transform = new HashMap<String, String>();
    boolean whitelist = false;

    String line;
    String[] words;

    if (!(param = (getParameter("underlyingEvents"))).equals("")) {
      try {
        underlyingEvents = EventDriverFactory.getEventDriver(param);
      } catch (Exception e) {
        System.out.println("Error: cannot create EventDriver " + param);
        System.out.println(" -- Using NaiveWordEventSet");
        underlyingEvents = new NaiveWordEventDriver();
      }
    } else { // no underlyingEventsParameter, use NaiveWordEventSet
      underlyingEvents = new NaiveWordEventDriver();
    }

    if (!(param = (getParameter("filename"))).equals("")) {
      filename = param;
    } else { // no underlyingfilename,
      filename = null;
    }

    if (!(param = (getParameter("implicitWhiteList"))).equals("")) {
      if (param.equalsIgnoreCase("true")) {
        whitelist = true;
      }
    } else { // no underlyingfilename,
      whitelist = false;
    }

    EventSet es = underlyingEvents.createEventSet(ds);

    EventSet newEs = new EventSet();
    newEs.setAuthor(es.getAuthor());
    newEs.setNewEventSetID(es.getAuthor());

    BufferedReader br = null;

    if (filename != null) {
      try {
        FileInputStream fis = new FileInputStream(filename);
        br = new BufferedReader(new InputStreamReader(fis));

        while ((line = br.readLine()) != null) {
          if (line.length() > 0) {
            String sep = line.substring(0, 1);
            words = line.substring(1).split(sep, -1);
            if (words.length > 1) {
              transform.put(words[0], words[1]);
              System.out.println("Adding \"" + words[0] + "\" : \"" + words[1] + "\"");
            }
          }
        }

      } catch (IOException e) {
        // catch io errors from FileInputStream or readLine()
        System.out.println("Cannot open/read " + filename);
        System.out.println("IOException error! " + e.getMessage());
        transform = null;
      } finally {
        // if the file opened okay, make sure we close it
        if (br != null) {
          try {
            br.close();
          } catch (IOException ioe) {
          }
        }
      }
    } else {
      transform = null;
    }

    for (Event e : es) {
      String s = e.toString();
      if (transform == null) {
        newEs.addEvent(e);
      } else if (transform.containsKey(s)) {
        String newS = transform.get(s);
        if (newS.length() > 0) {
          newEs.addEvent(new Event(newS));
        }
      } else // s is not in transformation list
      if (whitelist == false) {
        // add only if no implicit whitelisting
        newEs.addEvent(e);
      } // otherwise add nothing
    }
    return newEs;
  }