Hello guys , I am asked in my assignment to make a program that accepts a text file as an example a novel and i have to sort each word as a PERSON or ORGANIZATION or LOCATION or O as in Other , example :
Microsoft/ORGANIZATION ,/O Nelly/PERSON !/O '/O
Now we notice that microsoft is and organitzation and "," is Other and Nelly is a person's name and so on ..
Now I am asked to return the numbers of tags in the text which is 4 in our case because we have (ORGANIZATION,PERSON,LOCATION,OTHER)
My question here is my logic true ? And since i made a map of String,String ; Is there any way that i can get the size of the values in our case the values are the organization etc.. ??
Thank you.
import java.io.File; import java.io.FileNotFoundException; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.Set; public class NovelDataMining { /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { Scanner console = new Scanner(new File( "C:\\Users\\User\\AppData\\Local\\Temp\\novel.txt")); System.out.println(numberOfTags(console)); } public static int numberOfTags(Scanner console) { Map<String, String> map = new HashMap<String, String>(); while (console.hasNext()) { String nextWord = console.next(); if(nextWord.substring(nextWord.length()-1, nextWord.length()).equalsIgnoreCase("O"))// Here we are checking if the String is of Other Type map.put(nextWord, "O"); if(nextWord.substring(nextWord.length()-1, nextWord.length()).equalsIgnoreCase("PERSON")) map.put(nextWord, "PERSON"); if(nextWord.substring(nextWord.length()-1, nextWord.length()).equalsIgnoreCase("ORGANIZATION")) map.put(nextWord, "ORGANIZATION"); if(nextWord.substring(nextWord.length()-1, nextWord.length()).equalsIgnoreCase("LOCATION")) map.put(nextWord, "LOCATION"); for (String word : map.keySet()){ } } return 0;// just to remove the compliation error } }