执行句法分析

@param termList     分词结果
@param beamWidth    柱搜索宽度
@param numOfThreads 多线程数
@return 句法树
978843
public CoNLLSentence parse(List<Term> termList, int beamWidth, int numOfThreads)
    {
        String[] words = new String[termList.size()];
        String[] tags = new String[termList.size()];
        int k = 0;
        for (Term term : termList)
        {
            words[k] = term.word;
            tags[k] = term.nature.toString();
            ++k;
        }

        Configuration bestParse;
        try
        {
            bestParse = parser.parse(words, tags, false, beamWidth, numOfThreads);
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
        CoNLLWord[] wordArray = new CoNLLWord[termList.size()];
        for (int i = 0; i < words.length; i++)
        {
            wordArray[i] = new CoNLLWord(i + 1, words[i], tags[i]);
        }
        for (int i = 0; i < words.length; i++)
        {
            wordArray[i].DEPREL = parser.idWord(bestParse.state.getDependent(i + 1));
            int index = bestParse.state.getHead(i + 1) - 1;
            if (index < 0 || index >= wordArray.length)
            {
                wordArray[i].HEAD = CoNLLWord.ROOT;
            }
            else
            {
                wordArray[i].HEAD = wordArray[index];
            }
        }
        return new CoNLLSentence(wordArray);
    }
676890
public void setSegmentList(FSArray v) {
    if (MMAXAnnotation_Type.featOkTst && ((MMAXAnnotation_Type)jcasType).casFeat_segmentList == null)
      jcasType.jcas.throwFeatMissing("segmentList", "de.julielab.jules.types.mmax.MMAXAnnotation");
    jcasType.ll_cas.ll_setRefValue(addr, ((MMAXAnnotation_Type)jcasType).casFeatCode_segmentList, jcasType.ll_cas.ll_getFSRef(v));}
832931
private static void getThreadGroups(ThreadGroup tg, List ltg) {
		try {
			final Field fgroups = ThreadGroup.class.getDeclaredField("groups");
			fgroups.setAccessible(true);
			ThreadGroup[] array = (ThreadGroup[]) fgroups.get(tg);
			if (array != null) {
				for (int i = 0; i < array.length; i++) {
					ThreadGroup element = array[i];
					if (!ltg.contains(element)) {
						CClassLoader.getThreadGroups(element, ltg);
						ltg.add(element);
					}
				}
			}
		} catch (Throwable ignore) {
		}
	}
1296083
@Beta
  @GwtIncompatible // concurrency
  public static ThreadFactory platformThreadFactory() {
    if (!isAppEngine()) {
      return Executors.defaultThreadFactory();
    }
    try {
      return (ThreadFactory)
          Class.forName("com.google_voltpatches.appengine.api.ThreadManager")
              .getMethod("currentRequestThreadFactory")
              .invoke(null);
    } catch (IllegalAccessException e) {
      throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
    } catch (NoSuchMethodException e) {
      throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
    } catch (InvocationTargetException e) {
      throw Throwables.propagate(e.getCause());
    }
  }
889380
private <E> void listSwap(E[] list, int a, int b) {
		final E tmp = list[a];
		list[a] = list[b];
		list[b] = tmp;
	}
366773
public List chunk(List toks, List tags) {
    bestSequence =
        beam.bestSequence(toks, new Object[] { (String[]) tags.toArray(new String[tags.size()]) });
    return bestSequence.getOutcomes();
  }
367591
@Override
  public void setNumThreadsForParsing(Integer numThreadsForParsing) {
    if (numThreadsForParsing == null) {
      this.numThreadsForParsing = Runtime.getRuntime().availableProcessors();
      return;
    }
    if (numThreadsForParsing < 1) {
      throw new IllegalArgumentException("The number of threads can not be less than 1.");
    }
    this.numThreadsForParsing = numThreadsForParsing;
  }
1223099
protected List<Term> decorateResultForIndexMode(List<Vertex> vertexList, WordNet wordNetAll)
    {
        List<Term> termList = new LinkedList<Term>();
        int line = 1;
        ListIterator<Vertex> listIterator = vertexList.listIterator();
        listIterator.next();
        int length = vertexList.size() - 2;
        for (int i = 0; i < length; ++i)
        {
            Vertex vertex = listIterator.next();
            Term termMain = convert(vertex);
            termList.add(termMain);
            termMain.offset = line - 1;
            if (vertex.realWord.length() > 2)
            {
                // 过长词所在的行
                int currentLine = line;
                while (currentLine < line + vertex.realWord.length())
                {
                    Iterator<Vertex> iterator = wordNetAll.descendingIterator(currentLine);// 这一行的词，逆序遍历保证字典序稳定地由大到小
                    while (iterator.hasNext())// 这一行的短词
                    {
                        Vertex smallVertex = iterator.next();
                        if (
                            ((termMain.nature == Nature.mq && smallVertex.hasNature(Nature.q)) ||
                                smallVertex.realWord.length() >= config.indexMode)
                                && smallVertex != vertex // 防止重复添加
                                && currentLine + smallVertex.realWord.length() <= line + vertex.realWord.length() // 防止超出边界
                            )
                        {
                            listIterator.add(smallVertex);
                            Term termSub = convert(smallVertex);
                            termSub.offset = currentLine - 1;
                            termList.add(termSub);
                        }
                    }
                    ++currentLine;
                }
            }
            line += vertex.realWord.length();
        }

        return termList;
    }
274176
@SuppressWarnings("rawtypes")
    public void evaluateInstanceList(TransducerTrainer tt, InstanceList data,
            String description) {
        Transducer model = tt.getTransducer();
        int numCorrectTokens, totalTokens;
        int[] numTrueSegments, numPredictedSegments, numCorrectSegments;
        int allIndex = segmentStartTags.length;
        numTrueSegments = new int[allIndex + 1];
        numPredictedSegments = new int[allIndex + 1];
        numCorrectSegments = new int[allIndex + 1];

        totalTokens = numCorrectTokens = 0;
        for (int n = 0; n < numTrueSegments.length; n++)
            numTrueSegments[n] = numPredictedSegments[n] = numCorrectSegments[n] = 0;
        for (int i = 0; i < data.size(); i++) {
            Instance instance = data.get(i);
            Sequence input = (Sequence) instance.getData();
            // String tokens = null;
            // if (instance.getSource() != null)
            // tokens = (String) instance.getSource().toString();
            Sequence trueOutput = (Sequence) instance.getTarget();
            assert (input.size() == trueOutput.size());
            Sequence predOutput = model.transduce(input);
            assert (predOutput.size() == trueOutput.size());
            int trueStart, predStart; // -1 for non-start, otherwise index into
                                      // segmentStartTag

            boolean hasIncorrect = false;
            StringBuilder sentencePrint = new StringBuilder();

            for (int j = 0; j < trueOutput.size(); j++) {
                totalTokens++;
                if (trueOutput.get(j).equals(predOutput.get(j))) {
                    numCorrectTokens++;
                    if (printMissclassified)
                        sentencePrint.append(getText(input, j) + " ");

                } else if (printMissclassified) {// not predicted correctly
                    hasIncorrect = true;
                    sentencePrint.append("{{" + getText(input, j) + "}} ");
                }

                trueStart = predStart = -1;
                // Count true segment starts
                for (int n = 0; n < segmentStartTags.length; n++) {
                    if (segmentStartTags[n].equals(trueOutput.get(j))) {
                        numTrueSegments[n]++;
                        numTrueSegments[allIndex]++;
                        trueStart = n;
                        break;
                    }
                }
                // Count predicted segment starts
                for (int n = 0; n < segmentStartTags.length; n++) {
                    if (segmentStartTags[n].equals(predOutput.get(j))) {
                        numPredictedSegments[n]++;
                        numPredictedSegments[allIndex]++;
                        predStart = n;
                    }
                }
                if (trueStart != -1 && trueStart == predStart) {
                    // Truth and Prediction both agree that the same segment
                    // tag-type is starting now
                    int m;
                    boolean trueContinue = false;
                    boolean predContinue = false;
                    for (m = j + 1; m < trueOutput.size(); m++) {
                        trueContinue = segmentContinueTags[predStart]
                                .equals(trueOutput.get(m));
                        predContinue = segmentContinueTags[predStart]
                                .equals(predOutput.get(m));
                        if (!trueContinue || !predContinue) {
                            if (trueContinue == predContinue) {
                                // They agree about a segment is ending somehow
                                numCorrectSegments[predStart]++;
                                numCorrectSegments[allIndex]++;
                            }
                            break;
                        }
                    }
                    // for the case of the end of the sequence
                    if (m == trueOutput.size()) {
                        if (trueContinue == predContinue) {
                            numCorrectSegments[predStart]++;
                            numCorrectSegments[allIndex]++;
                        }
                    }
                }
            }
            if (hasIncorrect && printMissclassified)
                System.out.println(sentencePrint.toString());
        }

        tokenAccuracy = ((double) numCorrectTokens) / totalTokens;
        for (int n = 0; n < numCorrectSegments.length; n++) {
            if (!(n < allIndex)) {// only "OVERALL"
                precision = numPredictedSegments[n] == 0 ? 1
                        : ((double) numCorrectSegments[n])
                                / numPredictedSegments[n];
                recall = numTrueSegments[n] == 0 ? 1
                        : ((double) numCorrectSegments[n]) / numTrueSegments[n];
                f1 = recall + precision == 0.0 ? 0.0
                        : (2.0 * recall * precision) / (recall + precision);
            }
        }
    }
768075
protected static List<Term> convert(List<Vertex> vertexList, boolean offsetEnabled)
    {
        assert vertexList != null;
        assert vertexList.size() >= 2 : "这条路径不应当短于2" + vertexList.toString();
        int length = vertexList.size() - 2;
        List<Term> resultList = new ArrayList<Term>(length);
        Iterator<Vertex> iterator = vertexList.iterator();
        iterator.next();
        if (offsetEnabled)
        {
            int offset = 0;
            for (int i = 0; i < length; ++i)
            {
                Vertex vertex = iterator.next();
                Term term = convert(vertex);
                term.offset = offset;
                offset += term.length();
                resultList.add(term);
            }
        }
        else
        {
            for (int i = 0; i < length; ++i)
            {
                Vertex vertex = iterator.next();
                Term term = convert(vertex);
                resultList.add(term);
            }
        }
        return resultList;
    }
630291
public static String formatDisplayList(List<String> displayList, int termHeight, int termWidth) {
        if (displayList == null || displayList.size() < 1) {
            return "";
        }
        // make sure that termWidth is > 0
        if (termWidth < 1) {
            termWidth = 80; // setting it to default
        }
        int maxLength = 0;
        for (String completion : displayList) {
            if (completion.length() > termWidth) {
                maxLength = termWidth;
                break;
            }
            if (completion.length() > maxLength) {
                maxLength = completion.length();
            }
        }

        if (maxLength + 2 <= termWidth) {
            maxLength = maxLength + 2; // adding two spaces for better readability
        }
        int numColumns = termWidth / maxLength;
        if (numColumns > displayList.size()) // we dont need more columns than items
        {
            numColumns = displayList.size();
        }
        if (numColumns < 1) {
            numColumns = 1;
        }
        int numRows = displayList.size() / numColumns;

        // add a row if we cant display all the items
        if (numRows * numColumns < displayList.size()) {
            numRows++;
        }

        // create the completion listing
        StringBuilder completionOutput = new StringBuilder();
        for (int i = 0; i < numRows; i++) {
            for (int c = 0; c < numColumns; c++) {
                int fetch = i + (c * numRows);
                if (fetch < displayList.size()) {
                    completionOutput.append(padRight(maxLength, displayList.get(i + (c * numRows))));
                } else {
                    break;
                }
            }
            completionOutput.append(Config.getLineSeparator());
        }

        return completionOutput.toString();
    }
272525
def __launchThreads(self, numThreads):
        
        i = 0
        while i < numThreads:
            self.__logger.debug("Launching thread number " +
                                str(i))
            i += 1
            newThr = Thread(target=self.__processUsers)
            newThr.setDaemon(True)
            self.__threads.add(newThr)
            newThr.start()
1166913
private static void par_ief(CompList<?> t, int numproc) throws Exception {
        if (numproc < 1) {
            throw new IllegalArgumentException("numproc");
        }
        final CountDownLatch latch = new CountDownLatch(t.list().size());
//        final ExecutorService e = Executors.newFixedThreadPool(numproc);
        for (final Compound c : t) {
            e.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        ComponentAccess.callAnnotated(c, Initialize.class, true);
                        c.execute();
                        ComponentAccess.callAnnotated(c, Finalize.class, true);
                    } catch (Throwable E) {
                        e.shutdownNow();
                    }
                    latch.countDown();
                }
            });
        }
        latch.await();
//        e.shutdown();
    }
577307
public void writeListBeginning(final OutputStream result) throws IOException {
        result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
        if(this.inTable) {
            result.write(RtfParagraph.IN_TABLE);
        }
        switch (this.alignment) {
            case Element.ALIGN_LEFT:
                result.write(RtfParagraphStyle.ALIGN_LEFT);
                break;
            case Element.ALIGN_RIGHT:
                result.write(RtfParagraphStyle.ALIGN_RIGHT);
                break;
            case Element.ALIGN_CENTER:
                result.write(RtfParagraphStyle.ALIGN_CENTER);
                break;
            case Element.ALIGN_JUSTIFIED:
            case Element.ALIGN_JUSTIFIED_ALL:
                result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
                break;
        }
        writeIndentation(result);
        result.write(RtfFont.FONT_SIZE);
        result.write(intToByteArray(fontNumber.getFontSize() * 2));
        if(this.symbolIndent > 0) {
            result.write(LIST_LEVEL_SYMBOL_INDENT);
            result.write(intToByteArray(this.leftIndent));
        }
    }
85800
public static String formatDisplayList(String[] displayList, int termHeight, int termWidth) {
        return formatDisplayList(Arrays.asList(displayList), termHeight, termWidth);
    }
429945
private boolean isTermTrackBreadth(Term t) {
        if (t instanceof TermLengthOrPercent) {
            return true;
        } else if (t instanceof TermIdent) {
            CSSProperty property = genericPropertyRaw(GridTemplateRowsColumns.class, null, (TermIdent) t);
            return property == GridTemplateRowsColumns.AUTO
                    || property == GridTemplateRowsColumns.MIN_CONTENT
                    || property == GridTemplateRowsColumns.MAX_CONTENT;
        }
        return false;
    }
168835
public static FutureRowCount applyPageList(MultivaluedMap<String, String> queryParams, Query query) {

        FutureRowCount futureRowCount = fetchRowCount(queryParams, query);

        applyPageConfig(queryParams, query);

        return futureRowCount;
    }