Package org.apache.stanbol.enhancer.engines.sentiment.api

Examples of org.apache.stanbol.enhancer.engines.sentiment.api.SentimentClassifier


    /** bind method for {@link #classifiers} */
    protected void bindClassifier(SentimentClassifier classifier){
        log.info("  ... bind Sentiment Classifier {} for language {}",
            classifier.getClass().getSimpleName(),classifier.getLanguage());
        synchronized (classifiers) {
            SentimentClassifier old = classifiers.put(classifier.getLanguage(), classifier);
            if(old != null){
                log.warn("Replaced Sentiment Classifier for language {} (old: {}, new: {}",
                    new Object[]{old.getLanguage(),old,classifier});
            }
        }
    }
View Full Code Here


    }
    /** unbind method for {@link #classifiers} */
    protected void unbindClassifier(SentimentClassifier classifier){
        String lang = classifier.getLanguage();
        synchronized (classifiers) {
            SentimentClassifier current = classifiers.remove(lang);
            if(!classifier.equals(current) //the current is not the parsed one
                    && current != null){
                classifiers.put(lang,current); //re-add the value
            } else {
                log.info("  ... unbind Sentiment Classifier {} for language {}",
View Full Code Here

     */
    @Override
    public void computeEnhancements(ContentItem ci) throws EngineException {
        AnalysedText analysedText = getAnalysedText(this,ci, true);
        String language = getLanguage(this, ci, true);
        SentimentClassifier classifier = classifiers.get(language);
        if(classifier == null){
            throw new IllegalStateException("Sentiment Classifier for language '"
                + language +"' not available. As this is also checked in "
                + " canEnhance this may indicate an Bug in the used "
                + "EnhancementJobManager!");
        }
        //TODO: locking for AnalysedText not yet defined
//        ci.getLock().writeLock().lock();
//        try {
        Iterator<Token> tokens = analysedText.getTokens();
        while(tokens.hasNext()){
            Token token = tokens.next();
            Set<LexicalCategory> cats = null;
            boolean process = false;
            if(!adjectivesOnly){
                process = true;
                Value<PosTag> posTag = token.getAnnotation(NlpAnnotations.POS_ANNOTATION);
                if(posTag != null && posTag.probability() == Value.UNKNOWN_PROBABILITY
                        || posTag.probability() >= (minPOSConfidence/2.0)){
                    cats = classifier.getCategories(posTag.value());
                } else { //no POS tags or probability to low
                    cats = Collections.emptySet();
                }
            } else { //check PosTags if we need to lookup this word
                Iterator<Value<PosTag>> posTags = token.getAnnotations(NlpAnnotations.POS_ANNOTATION).iterator();
                boolean ignore = false;
                while(!ignore && !process && posTags.hasNext()) {
                    Value<PosTag> value = posTags.next();
                    PosTag tag = value.value();
                    cats = classifier.getCategories(tag);
                    boolean state = cats.contains(LexicalCategory.Adjective)
                            || cats.contains(LexicalCategory.Noun);
                    ignore = !state && (value.probability() == Value.UNKNOWN_PROBABILITY ||
                            value.probability() >= minPOSConfidence);
                    process = state && (value.probability() == Value.UNKNOWN_PROBABILITY ||
                            value.probability() >= (minPOSConfidence/2.0));
                }
            } //else process all tokens ... no POS tag checking needed
            if(process){
                String word = token.getSpan();
                double sentiment = 0.0;
                if(cats.isEmpty()){
                    sentiment = classifier.classifyWord(null, word);
                } else { //in case of multiple Lexical Cats
                    //we build the average over NOT NULL sentiments for the word
                    int catSentNum = 0;
                    for(LexicalCategory cat : cats){
                        double catSent = classifier.classifyWord(cat, word);
                        if(catSent != 0.0){
                            catSentNum++;
                            sentiment = sentiment + catSent;
                        }
                    }
View Full Code Here

    /** bind method for {@link #classifiers} */
    protected void bindClassifier(SentimentClassifier classifier){
        log.info("  ... bind Sentiment Classifier {} for language {}",
            classifier.getClass().getSimpleName(),classifier.getLanguage());
        synchronized (classifiers) {
            SentimentClassifier old = classifiers.put(classifier.getLanguage(), classifier);
            if(old != null){
                log.warn("Replaced Sentiment Classifier for language {} (old: {}, new: {}",
                    new Object[]{old.getLanguage(),old,classifier});
            }
        }
    }
View Full Code Here

    }
    /** unbind method for {@link #classifiers} */
    protected void unbindClassifier(SentimentClassifier classifier){
        String lang = classifier.getLanguage();
        synchronized (classifiers) {
            SentimentClassifier current = classifiers.remove(lang);
            if(!classifier.equals(current) //the current is not the parsed one
                    && current != null){
                classifiers.put(lang,current); //re-add the value
            } else {
                log.info("  ... unbind Sentiment Classifier {} for language {}",
View Full Code Here

     */
    @Override
    public void computeEnhancements(ContentItem ci) throws EngineException {
        AnalysedText analysedText = getAnalysedText(this,ci, true);
        String language = getLanguage(this, ci, true);
        SentimentClassifier classifier = classifiers.get(language);
        if(classifier == null){
            throw new IllegalStateException("Sentiment Classifier for language '"
                + language +"' not available. As this is also checked in "
                + " canEnhance this may indicate an Bug in the used "
                + "EnhancementJobManager!");
        }
        //TODO: locking for AnalysedText not yet defined
//        ci.getLock().writeLock().lock();
//        try {
        Iterator<Token> tokens = analysedText.getTokens();
        while(tokens.hasNext()){
            Token token = tokens.next();
            boolean process = !adjectivesOnly;
            if(!process){ //check POS types
                Iterator<Value<PosTag>> posTags = token.getAnnotations(NlpAnnotations.POS_ANNOTATION).iterator();
                boolean ignore = false;
                while(!ignore && !process && posTags.hasNext()) {
                    Value<PosTag> value = posTags.next();
                    PosTag tag = value.value();
                    boolean state = classifier.isAdjective(tag) || classifier.isNoun(tag);
                    ignore = !state && value.probability() >= minPOSConfidence;
                    process = state && value.probability() >= (minPOSConfidence/2.0);
                }
            } //else process all tokens ... no POS tag checking needed
            if(process){
                double sentiment = classifier.classifyWord(token.getSpan());
                if(sentiment != 0.0){
                    token.addAnnotation(SENTIMENT_ANNOTATION, new Value<Double>(sentiment));
                } //else do not set sentiments with 0.0
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.engines.sentiment.api.SentimentClassifier

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.