Example #1
0
  public List<SPOTriplet> sentence2triplets(String sentence) {
    List<SPOTriplet> triplets = new ArrayList<SPOTriplet>();
    LinkGrammar.parse(sentence);
    int num_linkages = LinkGrammar.getNumLinkages();
    SPOTriplet triplet = new SPOTriplet();
    String alter_p = new String();
    Boolean ready = false;

    for (int l = 0; l < num_linkages; ++l) {

      LinkGrammar.makeLinkage(l);
      Linkage linkage = new Linkage();
      linkage.setLinkCost(LinkGrammar.getLinkageLinkCost());
      linkage.setNumViolations(LinkGrammar.getLinkageNumViolations());
      linkage.setDisjunctCost(LinkGrammar.getLinkageDisjunctCost());
      linkage.setLinkedWordCount(LinkGrammar.getNumWords());

      String[] disjuncts = new String[LinkGrammar.getNumWords()];
      String[] words = new String[LinkGrammar.getNumWords()];

      for (int k = 0; k < words.length; k++) {
        disjuncts[k] = LinkGrammar.getLinkageDisjunct(k);
        words[k] = LinkGrammar.getLinkageWord(k);
      }

      for (int k = 0; k < LinkGrammar.getNumLinks() && !ready; k++) {

        String c = LinkGrammar.getLinkLabel(k);
        if (c.charAt(0) == 'S') {
          triplet.p = LinkGrammar.getLinkageWord(k);
          alter_p = words[LinkGrammar.getLinkRWord(k)];
          triplet.s = words[LinkGrammar.getLinkLWord(k)];
        }

        if (c.charAt(0) == 'O') {
          triplet.o = words[LinkGrammar.getLinkRWord(k)];

          if (triplet.p.equals(words[LinkGrammar.getLinkRWord(k)])) {
            triplet.cut();
            triplets.add(triplet);
            ready = true;
            break;
          } else if (alter_p.equals(words[LinkGrammar.getLinkRWord(k)])) {
            triplet.p = alter_p;
            triplet.cut();
            triplets.add(triplet);
            ready = true;
            break;
          }
        }
      }
    }

    return triplets;
  }
Example #2
0
 public Linkage copy() {
   Linkage dst = new Linkage();
   copyValues(dst);
   dst.author = author == null ? null : author.copy();
   if (item != null) {
     dst.item = new ArrayList<LinkageItemComponent>();
     for (LinkageItemComponent i : item) dst.item.add(i.copy());
   }
   ;
   return dst;
 }