001    /***************************************************************************/
002    /*  Copyright (C) 2010-2011, Sebastian Hellmann                            */
003    /*  Note: If you need parts of NLP2RDF in another licence due to licence   */
004    /*  incompatibility, please mail hellmann@informatik.uni-leipzig.de        */
005    /*                                                                         */
006    /*  This file is part of NLP2RDF.                                          */
007    /*                                                                         */
008    /*  NLP2RDF is free software; you can redistribute it and/or modify        */
009    /*  it under the terms of the GNU General Public License as published by   */
010    /*  the Free Software Foundation; either version 3 of the License, or      */
011    /*  (at your option) any later version.                                    */
012    /*                                                                         */
013    /*  NLP2RDF is distributed in the hope that it will be useful,             */
014    /*  but WITHOUT ANY WARRANTY; without even the implied warranty of         */
015    /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the           */
016    /*  GNU General Public License for more details.                           */
017    /*                                                                         */
018    /*  You should have received a copy of the GNU General Public License      */
019    /*  along with this program. If not, see <http://www.gnu.org/licenses/>.   */
020    /***************************************************************************/
021    
022    package org.nlp2rdf.implementation.snowball;
023    
024    import com.hp.hpl.jena.ontology.OntModel;
025    import org.nlp2rdf.core.ErrorHandling;
026    import org.nlp2rdf.core.URIGenerator;
027    import org.nlp2rdf.core.util.URIGeneratorHelper;
028    import org.nlp2rdf.webservice.NIFParameters;
029    import org.nlp2rdf.webservice.NIFServlet;
030    import org.slf4j.Logger;
031    import org.slf4j.LoggerFactory;
032    
033    public class NIFStemmer extends NIFServlet {
034        private static Logger log = LoggerFactory.getLogger(NIFStemmer.class);
035    
036        @Override
037        public void execute(NIFParameters nifParameters, OntModel model) throws Exception {
038    
039            String stemmer = (nifParameters.getParameterMap().get("stemmer") == null) ? "PorterStemmer" : nifParameters.getParameterMap().get("stemmer");
040            SnowballStemmer ss = new SnowballStemmer(stemmer);
041            if (nifParameters.inputWasText()) {
042                URIGenerator uriGenerator = URIGeneratorHelper.determineGenerator(nifParameters.getUriRecipe(), nifParameters.getContextLength());
043                ss.processText(nifParameters.getPrefix(), uriGenerator, nifParameters.getInputAsText(), model);
044            } else if (nifParameters.inputWasRDF()) {
045                ss.processNIFModel(model);
046            } else {
047                ErrorHandling.createError(true, nifParameters.getPrefix(), "Could not determine whether input was text or rdf", model);
048            }
049            log.debug("returning " + model.size() + " triples");
050        }
051    
052    
053    }