Revision: 7852 http://languagetool.svn.sourceforge.net/languagetool/?rev=7852&view=rev Author: dnaber Date: 2012-08-12 22:29:18 +0000 (Sun, 12 Aug 2012) Log Message: ----------- HTTP API: the XML output has now been extended to include the category of the match
Modified Paths: -------------- trunk/JLanguageTool/CHANGES.txt trunk/JLanguageTool/src/java/org/languagetool/tools/StringTools.java trunk/JLanguageTool/src/resource/api-output.dtd trunk/JLanguageTool/src/test/org/languagetool/MainTest.java trunk/JLanguageTool/src/test/org/languagetool/tools/StringToolsTest.java Modified: trunk/JLanguageTool/CHANGES.txt =================================================================== --- trunk/JLanguageTool/CHANGES.txt 2012-08-12 21:16:29 UTC (rev 7851) +++ trunk/JLanguageTool/CHANGES.txt 2012-08-12 22:29:18 UTC (rev 7852) @@ -58,11 +58,13 @@ -stand-alone GUI: rules can now be disabled and enabled again with a single click + -stand-alone GUI: copy and paste from the result area now keeps line breaks (Sourceforge + bug #3554842) + -HTTP API: "+" was incorrectly removed from input (Sourceforge bug #3543914), patch by Sourceforge user hiddenspirit - -stand-alone GUI: copy and paste from the result area now keeps line breaks (Sourceforge - bug #3554842) + -HTTP API: the XML output has been extended to include the category of the match 1.8 (2012-06-30) Modified: trunk/JLanguageTool/src/java/org/languagetool/tools/StringTools.java =================================================================== --- trunk/JLanguageTool/src/java/org/languagetool/tools/StringTools.java 2012-08-12 21:16:29 UTC (rev 7851) +++ trunk/JLanguageTool/src/java/org/languagetool/tools/StringTools.java 2012-08-12 22:29:18 UTC (rev 7852) @@ -30,6 +30,7 @@ import org.languagetool.Language; import org.languagetool.gui.ContextTools; +import org.languagetool.rules.Category; import org.languagetool.rules.RuleMatch; import org.languagetool.rules.patterns.PatternRule; @@ -370,6 +371,10 @@ + escapeXMLForAPIOutput(match.getRule().getUrl().toString()) + "\""); } + final Category category = match.getRule().getCategory(); + if (category != null) { + xml.append(" category=\"" + category.getName() + "\""); + } xml.append("/>\n"); } if (xmlMode == XmlPrintMode.END_XML || xmlMode == XmlPrintMode.NORMAL_XML) { Modified: trunk/JLanguageTool/src/resource/api-output.dtd =================================================================== --- trunk/JLanguageTool/src/resource/api-output.dtd 2012-08-12 21:16:29 UTC (rev 7851) +++ trunk/JLanguageTool/src/resource/api-output.dtd 2012-08-12 22:29:18 UTC (rev 7852) @@ -59,6 +59,9 @@ <!-- The url with additional information that may be given --> <!ATTLIST error url CDATA #IMPLIED> +<!-- The category of the match, if any : --> +<!ATTLIST error category CDATA #IMPLIED> + <!-- Note that the XML output may contain XML comments with additional information like timing and debugging information. These can be ignored. --> Modified: trunk/JLanguageTool/src/test/org/languagetool/MainTest.java =================================================================== --- trunk/JLanguageTool/src/test/org/languagetool/MainTest.java 2012-08-12 21:16:29 UTC (rev 7851) +++ trunk/JLanguageTool/src/test/org/languagetool/MainTest.java 2012-08-12 22:29:18 UTC (rev 7852) @@ -178,7 +178,9 @@ Main.main(args); String output = new String(this.out.toByteArray()); - assertTrue(output.contains("<error fromy=\"4\" fromx=\"5\" toy=\"4\" tox=\"10\" ruleId=\"ENGLISH_WORD_REPEAT_RULE\" msg=\"Possible typo: you repeated a word\" replacements=\"is\" context=\"This is is a test of language tool. \" contextoffset=\"5\" errorlength=\"5\"/>")); + assertTrue(output.contains("<error fromy=\"4\" fromx=\"5\" toy=\"4\" tox=\"10\" " + + "ruleId=\"ENGLISH_WORD_REPEAT_RULE\" msg=\"Possible typo: you repeated a word\" replacements=\"is\" " + + "context=\"This is is a test of language tool. \" contextoffset=\"5\" errorlength=\"5\" category=\"Miscellaneous\"/>")); } //test line mode vs. para mode @@ -278,7 +280,7 @@ assertTrue(output.indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") == 0); assertTrue(output.contains("<error fromy=\"0\" fromx=\"8\" toy=\"0\" tox=\"10\" ruleId=\"EN_A_VS_AN\" " + "msg=\"Use 'a' instead of 'an' if the following word doesn't start with a vowel sound, e.g. 'a sentence', " + - "'a university'\" replacements=\"a\" context=\"This is an test. This is a test of of language tool. ...\" contextoffset=\"8\" errorlength=\"2\"/>")); + "'a university'\" replacements=\"a\" context=\"This is an test. This is a test of of language tool. ...\" contextoffset=\"8\" errorlength=\"2\" category=\"Miscellaneous\"/>")); } public void testGermanFileWithURL() throws Exception { @@ -312,11 +314,10 @@ assertTrue(output.contains("<error fromy=\"0\" fromx=\"8\" toy=\"0\" tox=\"20\" ruleId=\"BRAK_PRZECINKA_KTORY\" subId=\"5\"")); //This tests whether XML encoding is actually UTF-8: assertTrue(output.contains("msg=\"Brak przecinka w tym fragmencie zdania. Przecinek prawdopodobnie należy postawić tak: 'świnia, która'.\" replacements=\"świnia, która\" ")); - assertTrue(output.contains("context=\"To jest świnia która się ślini. \" contextoffset=\"8\" errorlength=\"12\"/>")); + assertTrue(output.contains("context=\"To jest świnia która się ślini. \" contextoffset=\"8\" errorlength=\"12\" category=\"Błędy interpunkcyjne\"/>")); } public void testPolishLineNumbers() throws Exception { - File input = populateFile( "Test.\n" + "Test.\n" + Modified: trunk/JLanguageTool/src/test/org/languagetool/tools/StringToolsTest.java =================================================================== --- trunk/JLanguageTool/src/test/org/languagetool/tools/StringToolsTest.java 2012-08-12 21:16:29 UTC (rev 7851) +++ trunk/JLanguageTool/src/test/org/languagetool/tools/StringToolsTest.java 2012-08-12 22:29:18 UTC (rev 7852) @@ -24,13 +24,18 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import junit.framework.TestCase; import org.languagetool.Language; +import org.languagetool.rules.Category; +import org.languagetool.rules.Rule; import org.languagetool.rules.RuleMatch; import org.languagetool.rules.en.AvsAnRule; +import org.languagetool.rules.patterns.Element; +import org.languagetool.rules.patterns.PatternRule; /** * @author Daniel Naber @@ -171,6 +176,25 @@ "</matches>\n", xml); } + public void testRuleMatchesToXMLWithCategory() throws IOException { + final List<RuleMatch> matches = new ArrayList<RuleMatch>(); + final String text = "This is a test sentence."; + final List<Element> elements = Collections.emptyList(); + final Rule patternRule = new PatternRule("MY_ID", Language.GERMAN, elements, "my description", "my message", "short message"); + patternRule.setCategory(new Category("MyCategory")); + final RuleMatch match = new RuleMatch(patternRule, 8, 10, "myMessage"); + match.setColumn(99); + match.setEndColumn(100); + match.setLine(44); + match.setEndLine(45); + matches.add(match); + final String xml = StringTools.ruleMatchesToXML(matches, text, 5, StringTools.XmlPrintMode.NORMAL_XML); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<matches>\n" + + "<error fromy=\"44\" fromx=\"98\" toy=\"45\" tox=\"99\" ruleId=\"MY_ID\" msg=\"myMessage\" replacements=\"\" context=\"...s is a test ...\" contextoffset=\"8\" errorlength=\"2\" category=\"MyCategory\"/>\n" + + "</matches>\n", xml); + } + public void testRuleMatchesWithUrlToXML() throws IOException { final List<RuleMatch> matches = new ArrayList<RuleMatch>(); final String text = "This is an test sentence. Here's another sentence with more text."; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Languagetool-cvs mailing list Languagetool-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/languagetool-cvs