Examples of NearestNeighborDriver


Examples of com.jgaap.classifiers.NearestNeighborDriver

   * EventSet, List<EventSet>)}.
   * @throws AnalyzeException
   */
  @Test
  public void testAnalyze() throws AnalyzeException {
    NearestNeighborDriver nearest = new NearestNeighborDriver();
    CosineDistance cosine = new CosineDistance();
    nearest.setDistance(cosine);

    EventSet known1 = new EventSet();
    EventSet known2 = new EventSet();
    EventSet unknown = new EventSet();

    Vector<Event> test1 = new Vector<Event>();
    test1.add(new Event("Mary", null));
    test1.add(new Event("had", null));
    test1.add(new Event("a", null));
    test1.add(new Event("little", null));
    test1.add(new Event("lamb", null));
    test1.add(new Event("whose", null));
    test1.add(new Event("fleece", null));
    test1.add(new Event("was", null));
    test1.add(new Event("white", null));
    test1.add(new Event("as", null));
    test1.add(new Event("snow.", null));
    known1.addEvents(test1);
    //known1.setAuthor("Mary");

    Vector<Event> test2 = new Vector<Event>();
    test2.add(new Event("Peter", null));
    test2.add(new Event("piper", null));
    test2.add(new Event("picked", null));
    test2.add(new Event("a", null));
    test2.add(new Event("pack", null));
    test2.add(new Event("of", null));
    test2.add(new Event("pickled", null));
    test2.add(new Event("peppers.", null));
    known2.addEvents(test2);
    //known2.setAuthor("Peter");

    Vector<Event> test3 = new Vector<Event>();
    test3.add(new Event("Mary", null));
    test3.add(new Event("had", null));
    test3.add(new Event("a", null));
    test3.add(new Event("little", null));
    test3.add(new Event("lambda", null));
    test3.add(new Event("whose", null));
    test3.add(new Event("syntax", null));
    test3.add(new Event("was", null));
    test3.add(new Event("white", null));
    test3.add(new Event("as", null));
    test3.add(new Event("snow.", null));
    unknown.addEvents(test3);

    List<Document> knowns = new ArrayList<Document>();
    Document knownDocument1 = new Document();
    knownDocument1.setAuthor("Mary");
    knownDocument1.addEventSet(null, known1);
    knowns.add(knownDocument1);
    Document knownDocument2 = new Document();
    knownDocument2.setAuthor("Peter");
    knownDocument2.addEventSet(null, known2);
    knowns.add(knownDocument2);
   
    Document unknownDocument = new Document();
    unknownDocument.addEventSet(null, unknown);

    System.out.println("There once was a lass from Nantucket");
    nearest.train(knowns);
    List<Pair<String, Double>> t = nearest.analyze(unknownDocument);
    String r = t.get(0).getFirst();

    String s = "Mary";

    assertTrue(r.startsWith(s));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.