Package edu.washington.cs.knowitall.nlp

Examples of edu.washington.cs.knowitall.nlp.ChunkedSentence


        String sentStr = "Michael McGinn is the mayor of Seattle.";

        // Looks on the classpath for the default model files.
        OpenNlpSentenceChunker chunker = new OpenNlpSentenceChunker();
        ChunkedSentence sent = chunker.chunkSentence(sentStr);

        // Prints out the (token, tag, chunk-tag) for the sentence
        System.out.println(sentStr);
        for (int i = 0; i < sent.getLength(); i++) {
            String token = sent.getToken(i);
            String posTag = sent.getPosTag(i);
            String chunkTag = sent.getChunkTag(i);
            System.out.println(token + " " + posTag + " " + chunkTag);
        }

        // Prints out extractions from the sentence.
        ReVerbExtractor reverb = new ReVerbExtractor();
View Full Code Here


     * <code>NpChunkArgumentExtractor</code> is <code>LEFT</code>, then returns all noun phrases to
     * the left of <code>rel</code>. If the mode is <code>RIGHT</code>, then returns all noun phrases
     * to the right of <code>rel</code>.
     */
    protected Collection<ChunkedArgumentExtraction> extractCandidates(ChunkedExtraction rel) {
        ChunkedSentence sent = rel.getSentence();
        Collection<Range> npChunkRanges = removeRangeOverlapWithRelation(rel, sent.getNpChunkRanges());
        Collection<ChunkedArgumentExtraction> args = new ArrayList<ChunkedArgumentExtraction>();
        for (Range npChunkRange : npChunkRanges) {
            if (acceptRange(rel, npChunkRange)) {
                ChunkedArgumentExtraction arg = new ChunkedArgumentExtraction(sent, npChunkRange, rel);
                args.add(arg);
View Full Code Here

        }
    }

    private boolean extrCoversPhrase(ChunkedBinaryExtraction e) {

        ChunkedSentence sent = e.getSentence();
        List<String> tokens = sent.getTokens();

        Range x = e.getArgument1().getRange();
        Range y = e.getArgument2().getRange();
        Range r = e.getRelation().getRange();
        boolean adj = x.isAdjacentTo(r) && r.isAdjacentTo(y);

        int xs = x.getStart();
        boolean leftOk = xs == 0 || tokens.get(xs - 1).equals(",")
                || tokens.get(xs - 1).equals(".");

        int l = sent.getLength() - 1;
        int yr = y.getLastIndex();
        boolean rightOk = yr == l || tokens.get(yr + 1).equals(",")
                || tokens.get(yr + 1).equals(".");

        return adj && leftOk && rightOk;
View Full Code Here

    private Predicate<ChunkedBinaryExtraction> that() {
        return new Predicate<ChunkedBinaryExtraction>() {
            @Override
            public boolean apply(ChunkedBinaryExtraction arg0) {

                ChunkedSentence sentence = arg0.getSentence();
                ChunkedArgumentExtraction arg2 = arg0.getArgument2();

                for (int i = arg2.getStart() + arg2.getLength(); i < sentence
                        .getLength(); ++i) {

                    if (sentence.getToken(i).equalsIgnoreCase("that")) {
                        return true;
                    }
                }

                return false;
View Full Code Here

    private Predicate<ChunkedBinaryExtraction> p2() {
        return new Predicate<ChunkedBinaryExtraction>() {
            @Override
            public boolean apply(ChunkedBinaryExtraction arg0) {

                ChunkedSentence sentence = arg0.getSentence();
                ChunkedArgumentExtraction arg2 = arg0.getArgument2();

                int i = arg2.getStart() + arg2.getLength();
                if (i < sentence.getLength()) {
                    String token = sentence.getToken(i);
                    if (!token.isEmpty() && !period.matcher(token).matches()
                            && punct.matcher(token).matches()) {

                        return true;
                    }
View Full Code Here

    }

    private boolean sentLength(ChunkedBinaryExtraction e, int lower, int upper) {
        final int a = lower;
        final int b = upper;
        ChunkedSentence sent = e.getSentence();
        int len = sent.getLength();
        return a <= len && len < b;
    }
View Full Code Here

            final String... givenTokens) {
        return new Predicate<ChunkedBinaryExtraction>() {
            @Override
            public boolean apply(ChunkedBinaryExtraction arg0) {

                ChunkedSentence sentence = arg0.getSentence();
                ChunkedArgumentExtraction arg1 = arg0.getArgument1();

                int i = arg1.getStart() - 1;
                if (i >= 0 && sentence.getLength() > 0) {
                    String token = sentence.getToken(i);
                    for (String givenTok : givenTokens) {
                        if (token.equals(givenTok)) {
                            return true;
                        }
                    }
View Full Code Here

    }

    private boolean npAfterArg2(ChunkedBinaryExtraction e) {
        ChunkedArgumentExtraction arg2 = e.getArgument2();
        int lastArg2 = arg2.getRange().getLastIndex();
        ChunkedSentence sent = arg2.getSentence();
        return lastArg2 + 1 < sent.getLength()
                && sent.getChunkTags().get(lastArg2 + 1).equals("B-NP");
    }
View Full Code Here

        ChunkedExtraction arg1 = e.getArgument1();
        int start = arg1.getRange().getStart();
        if (start == 0) {
            return false;
        } else {
            ChunkedSentence sent = arg1.getSentence();
            return sent.getChunkTags().get(start - 1).endsWith("-NP");
        }

    }
View Full Code Here

    protected Iterable<ChunkedExtraction> doMap(
            Iterable<ChunkedExtraction> extrs) {
        List<ChunkedExtraction> extrList = new ArrayList<ChunkedExtraction>();
        Iterables.addAll(extrList, extrs);
        if (extrList.size() > 1) {
            ChunkedSentence sent = extrList.get(0).getSentence();
            List<Range> ranges = new ArrayList<Range>(extrList.size());
            for (ChunkedExtraction e : extrList) {
                ranges.add(e.getRange());
            }
            List<Range> mergedRanges = mergeOverlapping(ranges);
View Full Code Here

TOP

Related Classes of edu.washington.cs.knowitall.nlp.ChunkedSentence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.