<commit_before>/*
 * This file is part of CoAnSys project.
 * Copyright (c) 2012-2015 ICM-UW
 * 
 * CoAnSys is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * CoAnSys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with CoAnSys. If not, see <http://www.gnu.org/licenses/>.
 */
package pl.edu.icm.coansys.kwdextraction;

import java.io.*;
import java.text.BreakIterator;
import java.util.Map.Entry;
import java.util.*;

import org.jdom.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.edu.icm.ceon.commons.CeonGeneralException;

import pl.edu.icm.cermine.PdfNLMContentExtractor;
import pl.edu.icm.cermine.PdfRawTextExtractor;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.coansys.commons.stopwords.Stopwords;
import pl.edu.icm.coansys.commons.stopwords.Stopwords.Lang;
import pl.edu.icm.coansys.models.DocumentProtos;
import pl.edu.icm.coansys.models.DocumentProtos.TextWithLanguage;
import pl.edu.icm.coansys.models.constants.ProtoConstants;
import pl.edu.icm.yadda.tools.textcat.LanguageIdentifierBean;

/**
 * Implementation of Rapid Automatic Keyword Extraction algorithm
 *
 * @author <NAME> <<EMAIL>>
 */
public class RakeExtractor {

    private enum ExtractionOption {

        CONTENT(true, false),
        ABSTRACT(false, true),
        CONTENT_AND_ABSTRACT(true, true);
        private boolean fromContent;
        private boolean fromAbstract;

        ExtractionOption(boolean fromContent, boolean fromAbstract) {
            this.fromContent = fromContent;
            this.fromAbstract = fromAbstract;
        }
    }
    
    private static final Logger logger = LoggerFactory.getLogger(RakeExtractor.class);
    private static final String ILLEGAL_CHARS = "[^\\p{L}0-9-'\\s]";
    private static final int DEFAULT_KEYWORDS_NUMBER = 8;
    private static final Map<Lang, Set<String>> stopwords;
    private String content;
    private Lang lang;
    private ExtractionOption extractionOption;<commit_msg>LanguageIdentifierBean package name infix changed from 'icm' to 'ceon' following changes in ceon-commons between 0.1.0 and 1.0.0<commit_after>/*
 * This file is part of CoAnSys project.
 * Copyright (c) 2012-2015 ICM-UW
 * 
 * CoAnSys is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * CoAnSys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with CoAnSys. If not, see <http://www.gnu.org/licenses/>.
 */
package pl.edu.icm.coansys.kwdextraction;

import java.io.*;
import java.text.BreakIterator;
import java.util.Map.Entry;
import java.util.*;

import org.jdom.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.edu.icm.ceon.commons.CeonGeneralException;

import pl.edu.icm.cermine.PdfNLMContentExtractor;
import pl.edu.icm.cermine.PdfRawTextExtractor;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.coansys.commons.stopwords.Stopwords;
import pl.edu.icm.coansys.commons.stopwords.Stopwords.Lang;
import pl.edu.icm.coansys.models.DocumentProtos;
import pl.edu.icm.coansys.models.DocumentProtos.TextWithLanguage;
import pl.edu.icm.coansys.models.constants.ProtoConstants;
import pl.edu.icm.ceon.tools.textcat.LanguageIdentifierBean;

/**
 * Implementation of Rapid Automatic Keyword Extraction algorithm
 *
 * @author <NAME> <<EMAIL>>
 */
public class RakeExtractor {

    private enum ExtractionOption {

        CONTENT(true, false),
        ABSTRACT(false, true),
        CONTENT_AND_ABSTRACT(true, true);
        private boolean fromContent;
        private boolean fromAbstract;

        ExtractionOption(boolean fromContent, boolean fromAbstract) {
            this.fromContent = fromContent;
            this.fromAbstract = fromAbstract;
        }
    }
    
    private static final Logger logger = LoggerFactory.getLogger(RakeExtractor.class);
    private static final String ILLEGAL_CHARS = "[^\\p{L}0-9-'\\s]";
    private static final int DEFAULT_KEYWORDS_NUMBER = 8;
    private static final Map<Lang, Set<String>> stopwords;
    private String content;
    private Lang lang;
    private ExtractionOption extractionOption;
{'fraction_non_alphanumeric': 0.08889332800639232, 'fraction_numerical': 0.0067918497802636835, 'mean_word_length': 3.9281496062992125, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4050613', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1470, 'n_words': 447}