Hello I have a text file which contains a dictionery of phrases. I also have another text file. I need to see if any dictionery phrases are inside my larger text file and return the phrases which are in the dictionery. Here is my code so far:
private static void doCompare(CharSequence Key) throws FileNotFoundException, IOException {
String fileString = new String(Files.readAllBytes(Paths.get("dictonery/AB.txt")), StandardCharsets.UTF_8);
Map<String, String> map = new HashMap<String, String>();
String entireFileText = new Scanner(new File("dictonery/annotate.txt"))
.useDelimiter("\\A").next();
map.put(fileString, "Finish");
for (String key : map.keySet()) {
if(fileString.contains(key)) {
BufferedWriter writer = null;
try
{
writer = new BufferedWriter( new FileWriter( "annotate/AB.txt"));
writer.write( key);
}
catch ( IOException e)
{
}
finally
{
try
{
if ( writer != null)
writer.close( );
}
catch ( IOException e)
{
}
}
}
}
At the moment the whole dictionery is returned. How can I get it so just the terms that are matched in the dictionery are returned. Thanks