Revisão 1778 trunk/CoGrOOBase/src/main/java/br/usp/pcs/lta/cogroo/grammarchecker/Cogroo.java

Cogroo.java (revision 1778)
83 83

  
84 84
	protected static final Logger LOGGER = Logger.getLogger(Cogroo.class);
85 85

  
86
	public Cogroo(RuntimeConfigurationI config) {

87
		if (LOGGER.isDebugEnabled()) {

88
			LOGGER.debug(">>> init()");

89
		}

86
	public Cogroo(RuntimeConfigurationI config) {
87
		if (LOGGER.isDebugEnabled()) {
88
			LOGGER.debug(">>> init()");
89
		}
90 90
		LOGGER.info("Loading Resources...");
91
		
91
		
92 92
		try {
93 93
			
94
			// Loads dictionaries.

95
			LOGGER.info("Loading Dictionaries...");

94
			// Loads dictionaries.
95
			LOGGER.info("Loading Dictionaries...");
96 96
			long start = System.nanoTime();
97
			this.tagDictionary = config.getTagDictionary();

98
			LOGGER.info("Dictionaries loaded in " + (System.nanoTime() - start)

99
					/ 1000000 + "ms");

100
			// Loads models.

101
			LOGGER.info("Loading Models...");

102
			long modelLoadingStart = System.nanoTime();

97
			this.tagDictionary = config.getTagDictionary();
98
			LOGGER.info("Dictionaries loaded in " + (System.nanoTime() - start)
99
					/ 1000000 + "ms");
100
			// Loads models.
101
			LOGGER.info("Loading Models...");
102
			long modelLoadingStart = System.nanoTime();
103 103
			start = modelLoadingStart;
104 104
			this.sentDetect = config.getSentenceDetector();
105 105
			if (LOGGER.isDebugEnabled()) {
106 106
				LOGGER.debug("   [Sentence Detector]\t\tmodel loaded in\t["
107 107
						+ (System.nanoTime() - start) / 1000000 + "ms]");
108 108
			}
109
			start = System.nanoTime();

110
			this.tokenizer = config.getTokenizer();

111
			if (LOGGER.isDebugEnabled()) {

112
				LOGGER.debug("   [Tokenizer]\t\tmodel loaded in\t["

113
						+ (System.nanoTime() - start) / 1000000 + "ms]");

114
			}

115
			start = System.nanoTime();

116
			this.nameFind = config.getNameFinder();

117
			if (LOGGER.isDebugEnabled()) {

118
				LOGGER.debug("   [Namefinder]\t\tmodel loaded in\t["

119
						+ (System.nanoTime() - start) / 1000000 + "ms]");

120
			}

121
			start = System.nanoTime();

122
			this.tagger = config.getPOSTagger();

123
			if (LOGGER.isDebugEnabled()) {

124
				LOGGER.debug("   [Tagger]\t\tmodel loaded in\t["

125
						+ (System.nanoTime() - start) / 1000000 + "ms]");

126
			}

127
			start = System.nanoTime();

109
			start = System.nanoTime();
110
			this.tokenizer = config.getTokenizer();
111
			if (LOGGER.isDebugEnabled()) {
112
				LOGGER.debug("   [Tokenizer]\t\tmodel loaded in\t["
113
						+ (System.nanoTime() - start) / 1000000 + "ms]");
114
			}
115
			start = System.nanoTime();
116
			this.nameFind = config.getNameFinder();
117
			if (LOGGER.isDebugEnabled()) {
118
				LOGGER.debug("   [Namefinder]\t\tmodel loaded in\t["
119
						+ (System.nanoTime() - start) / 1000000 + "ms]");
120
			}
121
			start = System.nanoTime();
122
			this.tagger = config.getPOSTagger();
123
			if (LOGGER.isDebugEnabled()) {
124
				LOGGER.debug("   [Tagger]\t\tmodel loaded in\t["
125
						+ (System.nanoTime() - start) / 1000000 + "ms]");
126
			}
127
			start = System.nanoTime();
128 128
			this.chunker = config.getChunker();
129
			
130
			if (LOGGER.isDebugEnabled()) {

131
				LOGGER.debug("   [Chunker]\t\tmodel loaded in\t["

132
						+ (System.nanoTime() - start) / 1000000 + "ms]");

133
			}

134
			start = System.nanoTime();

135
			this.shallowParser = config.getShallowParser();

136
			if (LOGGER.isDebugEnabled())

137
			{

138
				LOGGER.debug("   [Shallow parser]\tmodel loaded in\t["

139
						+ (System.nanoTime() - start) / 1000000 + "ms]");

140
			}

141
			LOGGER.info("Models loaded in "

142
					+ (System.nanoTime() - modelLoadingStart) / 1000000 + "ms");

143
		} catch (Exception e) {

144
			throw new RuntimeException("CoGrOO loading failed", e);

145
		}

146
		// Forces initialization of the rules subsystem.

129
			
130
			if (LOGGER.isDebugEnabled()) {
131
				LOGGER.debug("   [Chunker]\t\tmodel loaded in\t["
132
						+ (System.nanoTime() - start) / 1000000 + "ms]");
133
			}
134
			start = System.nanoTime();
135
			this.shallowParser = config.getShallowParser();
136
			if (LOGGER.isDebugEnabled())
137
			{
138
				LOGGER.debug("   [Shallow parser]\tmodel loaded in\t["
139
						+ (System.nanoTime() - start) / 1000000 + "ms]");
140
			}
141
			LOGGER.info("Models loaded in "
142
					+ (System.nanoTime() - modelLoadingStart) / 1000000 + "ms");
143
		} catch (Exception e) {
144
			throw new RuntimeException("CoGrOO loading failed", e);
145
		}
146
		// Forces initialization of the rules subsystem.
147 147
			LOGGER.info("Loading Rules...");
148 148
			long start = System.nanoTime();
149
			this.checker = config.getChecker();

150
			LOGGER.info("Rules loaded in " + (System.nanoTime() - start)

151
					/ 1000000 + "ms");

152
		LOGGER.info("Loading completed!");

153
		if (LOGGER.isDebugEnabled()) {

149
			this.checker = config.getChecker();
150
			LOGGER.info("Rules loaded in " + (System.nanoTime() - start)
151
					/ 1000000 + "ms");
152
		LOGGER.info("Loading completed!");
153
		if (LOGGER.isDebugEnabled()) {
154 154
			LOGGER.debug("<<< init()");
155
		}

156
	}

155
		}
156
	}
157 157

  
158 158
	/* (non-Javadoc)
159 159
	 * @see br.usp.pcs.lta.cogroo.grammarchecker.CogrooI#checkText(java.lang.String)
......
165 165
	public int checkFirstSentence(String paraText, List<Mistake> outMistakes) {
166 166
		CheckerResult res = analyseAndCheckText(paraText, true);
167 167
		outMistakes.addAll(res.mistakes);
168
		return res.sentences.get(0).getSentence().length();
168
                int end = res.sentences.get(0).getSpan().getEnd();
169
		return end;
169 170
	}
170 171
	
171 172
	public CheckerResult analyseAndCheckText(String text) {
......
181 182
		 */
182 183
		if (LOGGER.isDebugEnabled()) {
183 184
			LOGGER.debug(">>> checkAndGetSentence()");
184
			LOGGER.debug("Text entered: " + text);
185
			LOGGER.debug("Text entered: [" + text + "] (length: " + text.length() + ")");
185 186
		}
186 187
		List<Sentence> sentences = null;
187 188
		List<Mistake> mistakes = new ArrayList<Mistake>();
......
249 250
	public static void main(String[] args) {
250 251
		
251 252
		long start = System.nanoTime();
252
		CogrooI cogroo = new Cogroo(new LegacyRuntimeConfiguration()); // THE CoGrOO!

253
		CogrooI cogroo = new Cogroo(new LegacyRuntimeConfiguration()); // THE CoGrOO!
253 254
		System.out.println("Loading time ["
254 255
				+ ((System.nanoTime() - start) / 1000000) + "ms]");
255 256
		Scanner kb = new Scanner(System.in);

Exportar para Unified diff