Hello,
I am trying to write a program in Java that tags sentences from a text file. Each tag has an associated array of keywords. A tag is applied to a sentence if and only if the sentence contains one or more keywords belonging to the tag's array My aim is to output the sentences in a categorical manner, e.g. if a certain keyword is an a category, and that keyword is in the sentence, then that sentence should be able to go to into that category. This is just the basic of what I have done:
For e.g. I have two tags: faults, and adaption. In those tags' arrays, I have words such as Bugs, Fail etc, for faults, and Polish, Clean up for adaption. One of the sentence will be 'BUG found and fixed', which would go into the faults category, hence it will input the sentence after the heading fault as it contains the word 'bug'.
AndString[] fault = { "Misspelled", "Error", "Fixed", "Change",};
String[] adaption = {"Fixed comments", "Filters", "Polish","Adjust"};
This is the code that I have used to read the text file, and split the words:
{ try{ FileInputStream fstream = new FileInputStream("readthis.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String newread; while ((newread = br.readLine()) != null) { System.out.println( java.util.Arrays.toString( newread.split(" "))); } in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
Right now the output that I am getting is:
as this were the words in my text file, without the split.['This, bugs, needs, fixing']
['Cleaned, up, section, one']
['Fixed, typos']
['adjusted, the, code, to, make, it, look, simpler']
My next step is to use the arrays that I have got, and use the sentences above to put them in their category, either in Faults, or Adaption, vie the keywords. However, I have looked at HashMaps, but I don't know how to use the arrays with it.
Any help or suggestions is useful for me.
Thank you