当前位置: 首页>>代码示例>>Java>>正文


Java Sentence.getBegin方法代码示例

本文整理汇总了Java中de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence.getBegin方法的典型用法代码示例。如果您正苦于以下问题:Java Sentence.getBegin方法的具体用法?Java Sentence.getBegin怎么用?Java Sentence.getBegin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence的用法示例。


在下文中一共展示了Sentence.getBegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
@Override
public void process(JCas aJCas)
    throws AnalysisEngineProcessException
{
    for (Sentence sent : JCasUtil.select(aJCas, Sentence.class)) {
        TextClassificationSequence sequence = new TextClassificationSequence(aJCas,
                sent.getBegin(), sent.getEnd());
        sequence.addToIndexes();

        List<Token> tokens = JCasUtil.selectCovered(aJCas, Token.class, sent);

        for (Token token : tokens) {
            TextClassificationTarget target = new TextClassificationTarget(aJCas, token.getBegin(),
                    token.getEnd());
            target.setId(tcId++);
            target.setSuffix(token.getCoveredText());
            target.addToIndexes();

            TextClassificationOutcome outcome = new TextClassificationOutcome(aJCas,
                    token.getBegin(), token.getEnd());
            outcome.setOutcome(getTextClassificationOutcome(aJCas, target));
            outcome.addToIndexes();
        }

    }
}
 
开发者ID:Horsmann,项目名称:FlexTag,代码行数:27,代码来源:TcPosTaggingWrapper.java

示例2: getPrecedingSentences

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
/**
 * Returns a list of annotations of the same type preceding the given annotation
 *
 * @param jCas       jcas
 * @param annotation sentence
 * @return list of sentences sorted incrementally by position
 */
public static List<Sentence> getPrecedingSentences(JCas jCas, Sentence annotation)
{
    List<Sentence> result = new ArrayList<Sentence>();

    for (Sentence sentence : JCasUtil.select(getInitialView(jCas), Sentence.class)) {
        if (sentence.getBegin() < annotation.getBegin()) {
            result.add(sentence);
        }
    }

    Collections.sort(result, new Comparator<Sentence>()
    {
        @Override public int compare(Sentence o1, Sentence o2)
        {
            return o2.getBegin() - o1.getBegin();
        }
    });

    return result;
}
 
开发者ID:dkpro,项目名称:dkpro-argumentation,代码行数:28,代码来源:JCasUtil2.java

示例3: getSucceedingSentences

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
/**
 * Returns a list of annotations of the same type succeeding the given annotation
 *
 * @param jCas       jcas
 * @param annotation sentence
 * @return list of sentences sorted incrementally by position
 */
public static List<Sentence> getSucceedingSentences(JCas jCas, Sentence annotation)
{
    List<Sentence> result = new ArrayList<Sentence>();

    for (Sentence sentence : JCasUtil.select(getInitialView(jCas), Sentence.class)) {
        if (sentence.getBegin() > annotation.getBegin()) {
            result.add(sentence);
        }
    }

    Collections.sort(result, new Comparator<Sentence>()
    {
        @Override public int compare(Sentence o1, Sentence o2)
        {
            return o2.getBegin() - o1.getBegin();
        }
    });

    return result;
}
 
开发者ID:dkpro,项目名称:dkpro-argumentation,代码行数:28,代码来源:JCasUtil2.java

示例4: setFirstVisibleUnit

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
@Override
public void setFirstVisibleUnit(Sentence aFirstVisibleUnit)
{
    JCas jcas;
    try {
        jcas = aFirstVisibleUnit.getCAS().getJCas();
    }
    catch (CASException e) {
        throw new IllegalStateException("Unable to fetch JCas from CAS", e);
    }

    firstVisibleUnitAddress = WebAnnoCasUtil.getAddr(aFirstVisibleUnit);
    firstVisibleUnitBegin = aFirstVisibleUnit.getBegin();
    firstVisibleUnitEnd = aFirstVisibleUnit.getEnd();

    Sentence lastVisibleUnit = getLastSentenceInDisplayWindow(jcas, getAddr(aFirstVisibleUnit),
            getPreferences().getWindowSize());
    firstVisibleUnitIndex = WebAnnoCasUtil.getSentenceNumber(jcas,
            aFirstVisibleUnit.getBegin());
    lastVisibleUnitIndex = WebAnnoCasUtil.getSentenceNumber(jcas, lastVisibleUnit.getBegin());
    unitCount = select(jcas, Sentence.class).size();
    
    windowBeginOffset = aFirstVisibleUnit.getBegin();
    windowEndOffset = lastVisibleUnit.getEnd();
}
 
开发者ID:webanno,项目名称:webanno,代码行数:26,代码来源:AnnotatorStateImpl.java

示例5: getSentenceNumber

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
/**
 * Get the sentence number at this specific position
 *
 * @param aJcas
 *            the JCas.
 * @param aBeginOffset
 *            the begin offset.
 * @return the sentence number.
 */
public static int getSentenceNumber(JCas aJcas, int aBeginOffset)
{
    int sentenceNumber = 0;
    
    Collection<Sentence> sentences = select(aJcas, Sentence.class);
    if (sentences.isEmpty()) {
        throw new IndexOutOfBoundsException("No sentences");
    }
    
    for (Sentence sentence : select(aJcas, Sentence.class)) {
        if (sentence.getBegin() <= aBeginOffset && aBeginOffset <= sentence.getEnd()) {
            sentenceNumber++;
            break;
        }
        sentenceNumber++;
    }
    return sentenceNumber;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:28,代码来源:WebAnnoCasUtil.java

示例6: tokenize

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
public static void tokenize(JCas aJCas)
{
    BreakIterator bi = BreakIterator.getWordInstance(Locale.US);
    for (Sentence s : select(aJCas, Sentence.class)) {
        bi.setText(s.getCoveredText());
        int last = bi.first();
        int cur = bi.next();
        while (cur != BreakIterator.DONE) {
            int[] span = new int[] { last, cur };
            trim(s.getCoveredText(), span);
            if (!isEmpty(span[0], span[1])) {
                Token seg = new Token(aJCas, span[0] + s.getBegin(), span[1] + s.getBegin());
                seg.addToIndexes(aJCas);
            }
            last = cur;
            cur = bi.next();
        }
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:20,代码来源:ImportExportServiceImpl.java

示例7: getSentenceNumber

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
public static int getSentenceNumber(Sentence sentence, JCas jCas)
{
    ArrayList<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class));

    for (int i = 0; i < sentences.size(); i++) {
        Sentence s = sentences.get(i);

        if (s.getBegin() == sentence.getBegin()) {
            return i;
        }
    }

    throw new IllegalStateException();
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:15,代码来源:ArgumentPrinterUtils.java

示例8: collectSentenceIDs

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
public static TreeMap<Integer, Sentence> collectSentenceIDs(JCas jCas)
{
    // for each sentence, we'll collect all its annotations
    TreeMap<Integer, Sentence> result = new TreeMap<>();
    for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
        int sentenceID = sentence.getBegin();

        // sentence begin is its ID
        result.put(sentenceID, sentence);
    }

    return result;
}
 
开发者ID:UKPLab,项目名称:sigir2016-collection-for-focused-retrieval,代码行数:14,代码来源:Step12GolDataExporter.java

示例9: collectSentenceIDs

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
public static TreeMap<Integer, SortedMap<String, String>> collectSentenceIDs(JCas jCas)
{
    // for each sentence, we'll collect all its annotations
    TreeMap<Integer, SortedMap<String, String>> result = new TreeMap<>();
    for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
        int sentenceID = sentence.getBegin();

        // sentence begin is its ID
        result.put(sentenceID, new TreeMap<>());
    }

    return result;
}
 
开发者ID:UKPLab,项目名称:sigir2016-collection-for-focused-retrieval,代码行数:14,代码来源:Step9AgreementCollector.java

示例10: isSameSentence

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
/**
 * Check if the two given offsets are within the same sentence.
 *
 * @param aJcas
 *            the JCAs.
 * @param aReferenceOffset
 *            the reference offset.
 * @param aCompareOffset
 *            the comparison offset.
 * @return if the two offsets are within the same sentence.
 */
public static boolean isSameSentence(JCas aJcas, int aReferenceOffset, int aCompareOffset)
{
    // Trivial case
    if (aReferenceOffset == aCompareOffset) {
        return true;
    }

    int offset1 = Math.min(aReferenceOffset, aCompareOffset);
    int offset2 = Math.max(aReferenceOffset, aCompareOffset);

    // Scanning through sentences
    Iterator<Sentence> si = JCasUtil.iterator(aJcas, Sentence.class);
    while (si.hasNext()) {
        Sentence s = si.next();
        if (s.getBegin() <= offset1 && offset1 <= s.getEnd()) {
            return s.getBegin() <= offset2 && offset2 <= s.getEnd();
        }

        // Sentences are sorted. When we hit the first sentence that is beyond the reference
        // offset, we will never again find a sentence that contains it.
        if (offset1 < s.getBegin()) {
            return false;
        }
    }

    return false;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:39,代码来源:WebAnnoCasUtil.java

示例11: getCurrentSentence

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
/**
 * Get the current sentence based on the annotation begin/end offset
 *
 * @param aJCas
 *            the JCas.
 * @param aBegin
 *            the begin offset.
 * @param aEnd
 *            the end offset.
 * @return the sentence.
 */
public static Sentence getCurrentSentence(JCas aJCas, int aBegin, int aEnd)
{
    Sentence currentSentence = null;
    for (Sentence sentence : select(aJCas, Sentence.class)) {
        if (sentence.getBegin() <= aBegin && sentence.getEnd() > aBegin
                && sentence.getEnd() <= aEnd) {
            currentSentence = sentence;
            break;
        }
    }
    return currentSentence;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:24,代码来源:WebAnnoCasUtil.java

示例12: getSentence

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
/**
 * Get the  sentence based on the annotation begin offset
 *
 * @param aJCas
 *            the JCas.
 * @param aBegin
 *            the begin offset.
 * @return the sentence.
 */
public static Sentence getSentence(JCas aJCas, int aBegin)
{
    Sentence currentSentence = null;
    for (Sentence sentence : select(aJCas, Sentence.class)) {
        if (sentence.getBegin() <= aBegin && sentence.getEnd() > aBegin) {
            currentSentence = sentence;
            break;
        }
    }
    return currentSentence;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:21,代码来源:WebAnnoCasUtil.java

示例13: findWindowStartCenteringOnSelection

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
/**
 * Gets the address of the first sentence visible on screen in such a way that the specified
 * focus offset is centered on screen.
 *
 * @param aJcas
 *            the CAS object
 * @param aSentence
 *            the old sentence
 * @param aFocusOffset
 *            the actual offset of the sentence.
 * @param aProject
 *            the project.
 * @param aDocument
 *            the document.
 * @param aWindowSize
 *            the window size.
 * @return the ID of the first sentence.
 */
public static Sentence findWindowStartCenteringOnSelection(JCas aJcas, Sentence aSentence,
        int aFocusOffset, Project aProject, SourceDocument aDocument, int aWindowSize)
{
    if (aWindowSize == 1) {
        return aSentence;
    }

    // Seek the sentence that contains the current focus
    Sentence s = getSentence(aJcas, aFocusOffset);
    
    // If the focus is outside any sentence, then we just return the reference sentence.
    // This should actually never happen, but in case it does, we log a warning and try to
    // behave.
    if (s == null) {
        LOG.warn("Focus [{}] is outside any unit, using first unit.", aFocusOffset);
        return aSentence;
    }

    // Center sentence
    FSIterator<Sentence> si = seekByFs(aJcas, Sentence.class, s);
    if (aWindowSize == 2 && s.getBegin() > aSentence.getBegin()) {
        return s;
    }
    int count = 0;
    while (si.isValid() && count < (aWindowSize / 2)) {
        si.moveToPrevious();
        if (si.isValid()) {
            s = si.get();
        }

        count++;
    }

    return s;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:54,代码来源:WebAnnoCasUtil.java

示例14: check

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages)
{
    try {
        boolean ok = true;
        
        for (Token t : select(aCas.getJCas(), Token.class)) {
            if (t.getBegin() >= t.getEnd()) {
                aMessages.add(new LogMessage(this, LogLevel.ERROR,
                        "Token with illegal span: %s", t));
                ok = false;
            }
        }

        for (Sentence s : select(aCas.getJCas(), Sentence.class)) {
            if (s.getBegin() >= s.getEnd()) {
                aMessages.add(new LogMessage(this, LogLevel.ERROR,
                        "Sentence with illegal span: %s", s));
                ok = false;
            }
        }
        
        return ok;
    }
    catch (CASException e) {
        log.error("Unabled to access JCas", e);
        aMessages.add(new LogMessage(this, LogLevel.ERROR,
                "Unabled to access JCas", e.getMessage()));
        return false;
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:32,代码来源:NoZeroSizeTokensAndSentencesCheck.java

示例15: annotate

import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; //导入方法依赖的package包/类
private static void annotate(StandaloneArgument argument, PrintWriter outputTXTFile,
        Map<String, List<List<String>>> segmentedEDUs)
        throws IOException
{
    try {
        // original jcas, for automatic segmenting with tokens and sentences
        JCas originalJCas = initializeJCas(argument);

        SimplePipeline.runPipeline(originalJCas, getPipeline());

        // for re-annotation with manual sentences, paragraph, and tokens
        JCas segmentedJCas = initializeJCas(argument);
        copyParagraphAndTokenAnnotations(originalJCas, segmentedJCas);

        // now for each sentence collect tokens and run EDU segmenter
        for (Sentence sentence : JCasUtil.select(originalJCas, Sentence.class)) {

            List<Token> tokens = JCasUtil.selectCovered(Token.class, sentence);
            List<String> tokenWords = new ArrayList<>();

            for (Token token : tokens) {
                tokenWords.add(token.getCoveredText());
            }

            String text = StringUtils.join(tokenWords, " ");
            String sentenceID = argument.getId() + "_" + sentence.getBegin();

            // either output for external segmenting or annotate
            if (outputTXTFile != null && segmentedEDUs == null) {
                outputTXTFile.println(sentenceID + "\t" + text);
                System.out.println("Writing " + sentenceID);
            }
            else if (outputTXTFile == null && segmentedEDUs != null) {

                List<List<String>> collectedEDUs = segmentedEDUs.get(sentenceID);

                if (collectedEDUs == null) {
                    throw new IllegalStateException(
                            "Cannot find EDUs for sentence " + sentenceID);
                }

                reAnnotatedSentencesFromEDUs(segmentedJCas, collectedEDUs, tokenWords, tokens);
            }
            else {
                throw new IllegalStateException();
            }
        }

        // save back
        argument.setJCas(segmentedJCas);
    }
    catch (UIMAException | IOException e) {
        throw new IOException(e);
    }
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:56,代码来源:Step0bTextSegmenterA.java


注:本文中的de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence.getBegin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。