// Path: src/main/java/uk/ac/shef/dcs/oak/jate/model/CorpusImpl.java
// public class CorpusImpl implements Corpus {
// 	private static final Logger _logger = Logger.getLogger(CorpusImpl.class);
// 
// 	private final Set<Document> _docs;
// 
// 	public CorpusImpl(){
// 		_docs = new HashSet<Document>();
// 	}
// 
// 	public Iterator<Document> iterator(){
// 		return _docs.iterator();
// 	}
// 
// 	public CorpusImpl(String path){
// 		_docs=new HashSet<Document>();
// 		File targetFolder = new File(path);
// 		
// 		File[] files = targetFolder.listFiles();
// 		if ( files != null ) {
// 			for (File f : files) {
// 				try {
// 					this.add(new DocumentImpl(f.toURI().toURL()));
// 				} catch (MalformedURLException e) {
// 					_logger.error( "Error processing " + f, e );
// 				}
// 			}
// 		}
// 	}
// 
//    public boolean add(Document document){
// 	   return _docs.add(document);
//    }
// 
//    public boolean contains(Document document){
// 	   return _docs.contains(document);
//    }
// 
//    public int size() {
//       return _docs.size();
//    }
// 
//    public boolean remove(Document doc){
// 	   return _docs.remove(doc);
//    }
// 
// }
// 
// Path: src/main/java/uk/ac/shef/dcs/oak/jate/model/DocumentImpl.java
// public class DocumentImpl implements Document{
//    private static final Logger _logger = Logger.getLogger(DocumentImpl.class);
// 
// 	protected final URL _url;
// 
//    public DocumentImpl(URL url) {
// 	   _url = url;
//    }
// 
//    public URL getUrl() {
//       return _url;
//    }
// 
//    public String getContent() {
//       String content = null;
//       try {
//          content = UtilFiles.getContent(_url).toString();
//       } catch (IOException e) {
//          _logger.error( "I/O Exception", e );
//       }
//       return content;
//    }
// 
//    public String toString() {
//       return _url.toString();
//    }
// 
//    public boolean equals(Object o) {
//       if (this == o) return true;
//       if (o == null || getClass() != o.getClass()) return false;
//       final DocumentImpl that = (DocumentImpl) o;
// 
// 	   return that.getUrl().equals(getUrl());
// 
//    }
// 
//    public int hashCode() {
//       return _url.hashCode();
//    }
// }


import uk.ac.shef.dcs.oak.jate.model.Corpus;
import uk.ac.shef.dcs.oak.jate.model.CorpusImpl;
import uk.ac.shef.dcs.oak.jate.model.Document;
import uk.ac.shef.dcs.oak.jate.model.DocumentImpl;
import java.util.StringTokenizer;
import java.io.File;
import java.net.MalformedURLException;

package uk.ac.shef.dcs.oak.jate.util.counter;



/**
 * Count number of words in corpus/document/text.
 *
 * @author <a href="mailto:z.zhang@dcs.shef.ac.uk">Ziqi Zhang</a>
 */


public class WordCounter {

	public WordCounter(){
	}

	/**
	 * Count number of words in a corpus, delimited by a space character
	 * @param c
	 * @return
	 */
	public int countWords(final Corpus c){
		int total=0;
		for(Document doc:c){
			StringTokenizer tokenizer = new StringTokenizer(doc.getContent().replaceAll("\\s+"," ")
					.replaceAll("\\s+"," ")," ");
			total+=tokenizer.countTokens();
		}
		return total;
	}

	/**
	 * Count number of words in a document, delimited by a space character
	 * @param d
	 * @return
	 */
	public int countWords(final Document d){
		
		
		/*StringTokenizer tokenizer = new StringTokenizer(d.getContent().replaceAll("\\s+"," ")
					.replaceAll("\\s+"," ")," ");
		*/
		//modified part
		
		StringTokenizer tokenizer = new StringTokenizer(d.getContent(), "\r\n|\n");
		
		return tokenizer.countTokens();			
	}

	/**
	 * Main testing method.
	 * @param args args[0] is the path to directory containing files
	 */
	public static void main(String[] args) {
		File targetFolder = new File(args[0]);
      	File[] files = targetFolder.listFiles();
		if ( files == null ) {
			System.err.println( "Unable to find files in " + args[0] );
			return;
		}

// Path: src/main/java/uk/ac/shef/dcs/oak/jate/model/CorpusImpl.java
// public class CorpusImpl implements Corpus {
// 	private static final Logger _logger = Logger.getLogger(CorpusImpl.class);
// 
// 	private final Set<Document> _docs;
// 
// 	public CorpusImpl(){
// 		_docs = new HashSet<Document>();
// 	}
// 
// 	public Iterator<Document> iterator(){
// 		return _docs.iterator();
// 	}
// 
// 	public CorpusImpl(String path){
// 		_docs=new HashSet<Document>();
// 		File targetFolder = new File(path);
// 		
// 		File[] files = targetFolder.listFiles();
// 		if ( files != null ) {
// 			for (File f : files) {
// 				try {
// 					this.add(new DocumentImpl(f.toURI().toURL()));
// 				} catch (MalformedURLException e) {
// 					_logger.error( "Error processing " + f, e );
// 				}
// 			}
// 		}
// 	}
// 
//    public boolean add(Document document){
// 	   return _docs.add(document);
//    }
// 
//    public boolean contains(Document document){
// 	   return _docs.contains(document);
//    }
// 
//    public int size() {
//       return _docs.size();
//    }
// 
//    public boolean remove(Document doc){
// 	   return _docs.remove(doc);
//    }
// 
// }
// 
// Path: src/main/java/uk/ac/shef/dcs/oak/jate/model/DocumentImpl.java
// public class DocumentImpl implements Document{
//    private static final Logger _logger = Logger.getLogger(DocumentImpl.class);
// 
// 	protected final URL _url;
// 
//    public DocumentImpl(URL url) {
// 	   _url = url;
//    }
// 
//    public URL getUrl() {
//       return _url;
//    }
// 
//    public String getContent() {
//       String content = null;
//       try {
//          content = UtilFiles.getContent(_url).toString();
//       } catch (IOException e) {
//          _logger.error( "I/O Exception", e );
//       }
//       return content;
//    }
// 
//    public String toString() {
//       return _url.toString();
//    }
// 
//    public boolean equals(Object o) {
//       if (this == o) return true;
//       if (o == null || getClass() != o.getClass()) return false;
//       final DocumentImpl that = (DocumentImpl) o;
// 
// 	   return that.getUrl().equals(getUrl());
// 
//    }
// 
//    public int hashCode() {
//       return _url.hashCode();
//    }
// }


// Path: src/main/java/uk/ac/shef/dcs/oak/jate/util/counter/WordCounter.java
import uk.ac.shef.dcs.oak.jate.model.Corpus;
import uk.ac.shef.dcs.oak.jate.model.CorpusImpl;
import uk.ac.shef.dcs.oak.jate.model.Document;
import uk.ac.shef.dcs.oak.jate.model.DocumentImpl;
import java.util.StringTokenizer;
import java.io.File;
import java.net.MalformedURLException;

package uk.ac.shef.dcs.oak.jate.util.counter;



/**
 * Count number of words in corpus/document/text.
 *
 * @author <a href="mailto:z.zhang@dcs.shef.ac.uk">Ziqi Zhang</a>
 */


public class WordCounter {

	public WordCounter(){
	}

	/**
	 * Count number of words in a corpus, delimited by a space character
	 * @param c
	 * @return
	 */
	public int countWords(final Corpus c){
		int total=0;
		for(Document doc:c){
			StringTokenizer tokenizer = new StringTokenizer(doc.getContent().replaceAll("\\s+"," ")
					.replaceAll("\\s+"," ")," ");
			total+=tokenizer.countTokens();
		}
		return total;
	}

	/**
	 * Count number of words in a document, delimited by a space character
	 * @param d
	 * @return
	 */
	public int countWords(final Document d){
		
		
		/*StringTokenizer tokenizer = new StringTokenizer(d.getContent().replaceAll("\\s+"," ")
					.replaceAll("\\s+"," ")," ");
		*/
		//modified part
		
		StringTokenizer tokenizer = new StringTokenizer(d.getContent(), "\r\n|\n");
		
		return tokenizer.countTokens();			
	}

	/**
	 * Main testing method.
	 * @param args args[0] is the path to directory containing files
	 */
	public static void main(String[] args) {
		File targetFolder = new File(args[0]);
      	File[] files = targetFolder.listFiles();
		if ( files == null ) {
			System.err.println( "Unable to find files in " + args[0] );
			return;
		}

		Corpus c = new CorpusImpl();
