Example usage for org.apache.lucene.analysis.en EnglishMinimalStemmer stem

List of usage examples for org.apache.lucene.analysis.en EnglishMinimalStemmer stem

Introduction

In this page you can find the example usage for org.apache.lucene.analysis.en EnglishMinimalStemmer stem.

Prototype

@SuppressWarnings("fallthrough")
    public int stem(char s[], int len) 

Source Link

Usage

From source file:mediaevalsemanticvectors.MediaEvalSemanticVectors.java

public void run(String[] args) throws FileNotFoundException, IOException {
    topicsFile = args[0];/*from  w w  w  .j a  v  a 2s  .com*/

    File parentFolder = new File(topicsFile).getParentFile();

    BufferedReader br = new BufferedReader(new FileReader(topicsFile));
    String line = "";
    EnglishMinimalStemmer ems = new EnglishMinimalStemmer();
    while ((line = br.readLine()) != null) {
        StringTokenizer st = new StringTokenizer(line, "|");
        String topic = st.nextToken();
        String latitude = st.nextToken();
        String longitude = st.nextToken();
        String url = st.nextToken();
        String query = st.nextToken();
        allowedImages = new TreeSet<>();
        String imageListFilename = parentFolder.getAbsolutePath() + File.separator + "xml4solr.imagesLists"
                + File.separator + query + ".xml.images.txt";
        BufferedReader br1 = new BufferedReader(new FileReader(imageListFilename));
        String line1 = "";
        while ((line1 = br1.readLine()) != null) {
            allowedImages.add(line1.trim());
        }
        br1.close();
        ArrayList<String> stemmedQuery = new ArrayList<>();
        for (String term : query.split(" ")) {
            char[] termCharArray = term.toCharArray();
            int stemmedLength = ems.stem(termCharArray, term.length());
            stemmedQuery.add(new String(Arrays.copyOfRange(termCharArray, 0, stemmedLength)));

        }
        search(Arrays.copyOfRange(args, 1, args.length), stemmedQuery.toArray(new String[] {}), topic);

    }
    br.close();
}