/* * Copyright (C) 2015 UNIVERSITE JOSEPH FOURIER (Grenoble 1)/ Springer-Verlag GmbH * author Nguyen Minh Tien - minh-tien.nguyen@imag.fr * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package fr.imag.Scidetect.Checker; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.HashMap; /** * * @author tien */ public class Indexer { private Object content; public void index(String content, File textfile) throws FileNotFoundException { String filename = textfile.getName().substring(0,textfile.getName().lastIndexOf(".")); filename+=".txt"; String path = textfile.getParent(); String[] words = content.split(" "); //System.out.println(words.length); HashMap counter = new HashMap(); for (int i = 0; i < words.length; i++) { if (!counter.containsKey(words[i])) { counter.put(words[i], 1); } else { counter.put(words[i], counter.get(words[i]) + 1); } } File indexout = new File(path + "/INDEX-" + filename); // String filepath = (indexout.getPath()); PrintWriter out = new PrintWriter(indexout); for (String key : counter.keySet()) { out.println(key + "\t" + counter.get(key)); } out.close(); } }