Пример #1
0
  public static double getMI(String w1, String r, String w2) {
    GR gr = new GR();
    gr.setW1(w1);
    gr.setW2(w2);
    gr.setGR(r);

    return Math.log10(
        (getCount(gr) * getCountGR(r)) / (getCountLeft(w1, r) * getCountRight(w2, r)));
  }
Пример #2
0
  public static int getCount(GR gr) {
    int c = 0;
    Iterator<GR> iterator = memmodel.iterator();
    int i = 0;
    while (iterator.hasNext()) {
      if (iterator.next().isEqual(gr.getLeft(), gr.getGr(), gr.getRight())) c++;
    }

    return c;
  }
Пример #3
0
  public static Set<String> getLeftList(String w2, String gr) {
    Set<String> s = new TreeSet<String>();
    Iterator<GR> iterator = memmodel.iterator();

    while (iterator.hasNext()) {
      GR g = (GR) iterator.next();
      if (g.isRightEqual("online") && g.isGrEqual("dobj")) s.add(g.getLeft());
    }

    return s;
  }
Пример #4
0
  public static int getCountRight(String w2, String gr) {
    int c = 0;
    Iterator<GR> iterator = memmodel.iterator();
    int i = 0;
    while (iterator.hasNext()) {
      GR g = (GR) iterator.next();
      if (g.isRightEqual(w2) && g.isGrEqual(gr)) c++;
    }

    return c;
  }
Пример #5
0
  public static void main(String[] args) throws NullPointerException {
    VocabularyAnalyser va = new VocabularyAnalyser();
    String root = "/Users/kapila/Documents/repository/";

    memmodel = va.buildMemModel(root + "parsed");

    Iterator<GR> iterator = memmodel.iterator();
    int i = 0;
    while (iterator.hasNext()) {
      try {
        i++;
        // GR g= (GR) iterator.next();
        //			System.out.print(i);
        //			System.out.print(" ");
        // System.out.println( iterator.next().getLeft());

        GR g = (GR) iterator.next();
        if (g.isRightEqual("online") && g.isGrEqual("dobj")) System.out.println(g.toString());

      } catch (NullPointerException e) {
        System.out.println(e.getMessage());
      }
    }
    //
    //		GR g=new GR();
    //		g.setW1("purchase");
    //		g.setGR("dobj");
    //		g.setW2("online");
    //		System.out.println(getCount(g));
    //		System.out.println(getCountGR("dobj"));
    //		System.out.println(getCountLeft("purchase","dobj"));
    //		System.out.println(getCountLeft("online","dobj"));
    //		System.out.println(getMI("purchase","dobj","online"));
    //

    GR g2 = new GR();
    g2.setW1("buy");
    g2.setGR("dobj");
    g2.setW2("online");
    System.out.println(getCount(g2));
    System.out.println(getCountGR("dobj"));
    System.out.println(getCountLeft("buy", "dobj"));
    System.out.println(getCountLeft("online", "dobj"));
    System.out.println(getMI("buy", "dobj", "online"));

    Set left = getLeftList("online", "dobj");
    Iterator<String> it = left.iterator();
    while (it.hasNext()) {
      String s = it.next();
      System.out.println(s + "=" + getMI(s, "dobj", "online"));
    }

    //		Model rdfmodel=va.buildRdfModel(root+"rdfs");
    //		rdfmodel.write(System.out);
    //
    //		queryRdf q=new queryRdf(rdfmodel);
    // <http://rasp/rule:dobj>

    //		q.getTotal("?s","?p","?o");
    //		System.out.println("total-dobj");

    //		q.query("?s","gr:ncmod","?o");
    //		System.out.println("***");

    //		System.out.println("***");
    //		System.out.println(q.getTotal("?s","?p","?o"));
    //		System.out.println(q.getTotal("c:buy","gr:dobj","?o"));
    //		System.out.println(q.getTotal("c:purchase","gr:dobj","?o"));
    //		System.out.println(q.getTotal("?s","gr:dobj","c:online"));
    //		System.out.println(q.getTotal("c:buy","gr:dobj","c:online"));
    //		System.out.println(q.getTotal("c:purchase","gr:dobj","c:online"));
  }