Gets the best parse tree spanning the entire sentence.

@return
960262
public CfgParseTree getBestParseTree() {
    Factor rootMarginal = getMarginalEntries(0, chartSize() - 1);
    Assignment bestAssignment = rootMarginal.getMostLikelyAssignments(1).get(0);
    return getBestParseTree(bestAssignment.getOnlyValue());
  }
1058069
def _parse_sentencetree(self, tree, parent_node_id=None, ignore_traces=True):
        """"""
        def get_nodelabel(node):
            if isinstance(node, nltk.tree.Tree):
                return node.label()
            elif isinstance(node, unicode):
                return node.encode('utf-8')
            else:
                raise ValueError("Unexpected node type: {0}, {1}".format(type(node), node))

        root_node_id = self._node_id
        self.node[root_node_id]['label'] = get_nodelabel(tree)

        for subtree in tree:
            self._node_id += 1
            node_label = get_nodelabel(subtree)
            # unescape the node label, if necessary
            node_label = PTB_BRACKET_UNESCAPE.get(node_label, node_label)
            # TODO: refactor this, so we don't need to query this all the time
            if ignore_traces and node_label == '-NONE-': # ignore tokens annotated for traces
                continue
            if isinstance(subtree, nltk.tree.Tree):
                if len(subtree) > 1: # subtree is a syntactic category
                    node_attrs = {'label': node_label,
                                  self.ns+':cat': node_label}
                    layers = {self.ns, self.ns+':syntax'}
                else:  # subtree represents a token and its POS tag
                    node_attrs = {'label': node_label}
                    layers = {self.ns}

                edge_type = dg.EdgeTypes.dominance_relation
                self.add_node(self._node_id, layers=layers,
                              attr_dict=node_attrs)
                self.add_edge(root_node_id, self._node_id, edge_type=edge_type)

            else: # isinstance(subtree, unicode); subtree is a token
                # we'll have to modify the parent node of a token, since
                # in NLTK Trees, even a leaf node (with its POS tag) is
                # represented as a Tree (an iterator over a single unicode
                # string), e.g. ``Tree('NNS', ['prices'])``
                pos_tag = self.node[parent_node_id]['label']
                token_attrs = {
                    'label': node_label, self.ns+':token': node_label,
                    self.ns+':pos': pos_tag}
                self.node[parent_node_id].update(token_attrs)
                self.tokens.append(parent_node_id)

            if isinstance(subtree, nltk.tree.Tree):
                self._parse_sentencetree(subtree, parent_node_id=self._node_id)
892741
public List<List<IWord>> getComplexSentenceList()
    {
        List<List<IWord>> complexList = new LinkedList<List<IWord>>();
        for (Sentence sentence : sentenceList)
        {
            complexList.add(sentence.wordList);
        }

        return complexList;
    }
161348
public ProgramMetaData build(ParseTree tree)
	{

		int size = tree.getChildCount() - 1;
		List<Statement> ls = new ArrayList<Statement>(size);
		for (int i = 0; i < size; i++)
		{
			Statement st = parseStatment((ParserRuleContext) tree.getChild(i));
			if (st != null)
			{
				ls.add(st);
			}

		}

		if (pbCtx.current.gotoValue == IGoto.RETURN || pbCtx.current.gotoValue == IGoto.BREAK)
		{
			//如果顶级scope也有return 和break，则检测
			data.hasGoto = true;
		}

		pbCtx.anzlyszeGlobal();
		pbCtx.anzlyszeLocal();
		data.varIndexSize = pbCtx.varIndexSize;
		data.tempVarStartIndex = pbCtx.globalIndexMap.size();
		data.statements = ls.toArray(new Statement[0]);
		data.globalIndexMap = pbCtx.globalIndexMap;
		data.globalVarAttr = pbCtx.globaVarAttr;
		data.setTemplateRootScopeIndexMap(pbCtx.rootIndexMap);

		return data;

	}
751705
ParseTree toParseTree() {
    List<ParseTree> children = new ArrayList<ParseTree>();
    for (TreeNode child = latestChild; child != null; child = child.previous) {
      children.add(child.toParseTree());
    }
    Collections.reverse(children);
    return new ParseTree(name, beginIndex, endIndex, result, children);
  }
758866
protected static OptionParser getParser() {
            OptionParser parser = new OptionParser();
            // help options
            AdminParserUtils.acceptsHelp(parser);
            AdminParserUtils.acceptsUrl(parser);
            // optional options
            AdminParserUtils.acceptsConfirm(parser);
            return parser;
        }
860747
@Override
	public String getFullPredString()
	{
		if (valuetree.getPredicate() == null)
		{
			return "";
		}
		String result = valuetree.getPredicate().toString();
		return result;
	}
878656
public DependencyTree parse2T(String[][] tagg) {
		if(tagg==null)
			return null;
		return parse2T(tagg[0], tagg[1]);
	}
1024967
public List<Tokenizer.Token> tokenize(String sentence) {
      Sequence seq = Sequence.create(Chars.asList(sentence.toCharArray())
                                          .stream()
                                          .map(Object::toString));
      Labeling labels = model.label(seq);

      int n = sentence.length();
      int[][] spans = new int[n + 1][2];
      double[] best = new double[n + 1];
      best[0] = 1d;

      for (int i = 1; i <= n; i++) {
         for (int j = Math.max(0, i - maxSpanSize); j < i; j++) {
            int w = i - j;
            String span = sentence.substring(j, j + w);
            double score = scoreWord(j, j + w, span, labels);
            double segmentScore = multi(best[i - w], score);
            logFiner("'{0}' > '{1}' : {2} : {3}",
                     sentence.substring(spans[i - w][0], spans[i - w][1]),
                     span,
                     segmentScore,
                     best[i]);
            if (segmentScore >= best[i]) {
               best[i] = segmentScore;
               spans[i][0] = j;
               spans[i][1] = j + w;
            }
         }
      }
      int i = n;
      LinkedList<Tokenizer.Token> tokens = new LinkedList<>();
      while (i > 0) {
         String token = StringUtils.trim(sentence.substring(spans[i][0], spans[i][1]));
         if (!StringUtils.isNullOrBlank(token)) {
            tokens.addFirst(
               new Tokenizer.Token(token, TokenType.UNKNOWN, spans[i][0], spans[i][0] + token.length(), 0));
         }
         i = i - (spans[i][1] - spans[i][0]);
      }
      i = 0;
      for (Tokenizer.Token token : tokens) {
         token.index = i;
         i++;
      }

      return tokens;
   }
916157
protected AbcNode getParseTree(String abcString) {
		long startTime = System.currentTimeMillis();
		AbcGrammar grammar = AbcGrammar.getInstance();
		// AbcGrammar parser = Parboiled.createParser(AbcGrammar.class);
		ParsingResult<?> result = RecoveringParseRunner.run(grammar.AbcFile(),
				abcString);
		if (DEBUG) {
			System.out.println("Parse : "+(System.currentTimeMillis() - startTime) + "ms");
		}
		if (result.hasErrors()) {
			System.err.println("Parse errors: "
					+ result.parseErrors.size());
			/*Iterator it = result.parseErrors.iterator();
			while (it.hasNext()) {
				ParseError pe = (ParseError) it.next();
				System.err.println("- " + pe.getErrorMessage()
						+ "("+pe.getStartIndex()+"->"+pe.getEndIndex()+")");
			}*/
		}

		AbcNode abcRoot = new AbcNode(result.parseTreeRoot, result.inputBuffer,
				result.parseErrors, new AbcInputBuffer(abcString.toCharArray()));
		if (result.hasErrors() || DEBUG)
			debugTree(abcRoot);
		return abcRoot;
	}
675930
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "/parse", method = RequestMethod.GET)
  public String parse(@RequestParam("sentence") String sentence, HttpServletRequest request) {
    if (sentence == null || sentence.trim().isEmpty()) {
      return StringUtils.EMPTY;
    }

    sentence = sentence.trim();
    LOGGER.info("Parse [" + sentence + "]");
    DTree tree = PARSER.parse(sentence);

    DTreeEntity parseTreeEntity = new DTreeEntity(tree, "SAMPLE_AUTHOR");
    dNodeEntityRepository.save(parseTreeEntity.dNodeEntities);
    dTreeEntityRepository.save(parseTreeEntity);

    return "[" + toJSON(tree.get(0)) + "]";
  }
1087730
protected DCTree inlineText() throws ParseException {
        skipWhitespace();
        int pos = bp;
        int depth = 1;

        loop:
        while (bp < buflen) {
            switch (ch) {
                case '\n': case '\r': case '\f':
                    newline = true;
                    break;

                case ' ': case '\t':
                    break;

                case '{':
                    newline = false;
                    lastNonWhite = bp;
                    depth++;
                    break;

                case '}':
                    if (--depth == 0) {
                        return m.at(pos).Text(newString(pos, bp));
                    }
                    newline = false;
                    lastNonWhite = bp;
                    break;

                case '@':
                    if (newline)
                        break loop;
                    newline = false;
                    lastNonWhite = bp;
                    break;

                default:
                    newline = false;
                    lastNonWhite = bp;
                    break;
            }
            nextChar();
        }
        throw new ParseException("dc.unterminated.inline.tag");
    }
927975
public Context getSelectedContext() {
		SiteNode node = (SiteNode) treeContext.getLastSelectedPathComponent();
		if (node == null || node.isRoot()) {
			return null;
		}
		Target target = (Target) node.getUserObject();
		if (target != null) {
			return target.getContext();
		}
		return null;
	}
944831
public String getContent() {
		String content = "";
		
		NodeList list = dom.getChildNodes();
		for (int i=0;i<list.getLength();i++) {
			if (list.item(i) instanceof Text) {
				content += (list.item(i).getNodeValue());
			}
		}
		
		return content;
	}
1029702
public final Parser<T> atomic() {
    return new Parser<T>() {
      @Override public Parser<T> label(String name) {
        return Parser.this.label(name).atomic();
      }
      @Override boolean apply(ParseContext ctxt) {
        int at = ctxt.at;
        int step = ctxt.step;
        boolean r = Parser.this.apply(ctxt);
        if (r) ctxt.step = step + 1;
        else ctxt.setAt(step, at);
        return r;
      }
      @Override public String toString() {
        return Parser.this.toString();
      }
    };
  }
1224981
public @Nonnull String text() {
        return new NodeListSpliterator(node.getChildNodes()).stream()
                        .filter(it -> it instanceof Text)
                        .map(it -> ((Text) it).getNodeValue())
                        .collect(joining());
    }
1080043
public String max(BinaryTree<String> tree)  {
        return tree.match(new BinaryTree.MatchBlock<String, String>() {
           @Override
           public String _case(Node<String> x) {
               final String maxLeft = max(x.left);
               final String maxRight = max(x.right);

               return maxString(maxString(maxLeft, maxRight), x.value);
           }

           @Override
           public String _case(EmptyTree<String> x) {
              return null;
           }
        });
     }