source: other-projects/the-macronizer/trunk/src/main/java/org/atea/nlptools/macroniser/monogram/model/ListModel.java@ 35791

Last change on this file since 35791 was 35791, checked in by cstephen, 3 years ago

Add updated macroniser code. This is a significant change to the codebase:

  • Servlets now send JSON responses that are easier to consume from other services.
  • Error responses are better conveyed and more infomative.
  • Monogram components have been touched up. They now bubble errors up and, where applicable, implement relevant interfaces.
  • The JSP interface has been removed
  • The SQL logging functionality has been deleted. It wasn't used before.
  • Dependencies updated.
File size: 1.7 KB
Line 
1package org.atea.nlptools.macroniser.monogram.model;
2
3import java.io.BufferedReader;
4import java.io.IOException;
5import java.io.InputStreamReader;
6import java.io.Reader;
7import java.util.HashSet;
8import java.util.Set;
9
10/**
11 *
12 * @author tl113
13 */
14public class ListModel
15{
16 private final String CHARSET_ENCODING = "utf-8";
17 private final String path;
18 private final Set<String> specialConditionsList;
19
20 public ListModel(String path)
21 {
22 this.path = path;
23 this.specialConditionsList = new HashSet<String>();
24
25 init();
26 }
27
28 private void init()
29 {
30 BufferedReader reader = null;
31 try
32 {
33 final String filepath = path;
34 reader = new BufferedReader(
35 new InputStreamReader(getClass().getResourceAsStream(filepath), CHARSET_ENCODING)
36 );
37
38 String line;
39 while ((line = reader.readLine()) != null) {
40 specialConditionsList.add(line);
41 }
42 }
43 catch (IOException e)
44 {
45 e.printStackTrace();
46 }
47 finally
48 {
49 close(reader);
50 }
51
52 }
53
54 private void close(Reader reader)
55 {
56 if (reader != null)
57 {
58 try {
59 reader.close();
60 }
61 catch (IOException e) {
62 e.printStackTrace();
63 }
64 }
65 }
66
67 public Set<String> getMonogramProbabilities() {
68 return specialConditionsList;
69 }
70
71 public boolean contains(String s)
72 {
73 if(specialConditionsList.contains(s)) {
74 return true;
75 }
76
77 return false;
78 }
79}
Note: See TracBrowser for help on using the repository browser.