Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
add exception trace to log message for countWords; extra test strings
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Aug 12, 2011
1 parent c9ef7c6 commit 882dfd7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 11 additions & 3 deletions server/zanata-model/src/main/java/org/zanata/util/OkapiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public static LocaleId toOkapiLocale(org.zanata.common.LocaleId zanataLocale)
return LocaleId.fromBCP47(zanataLocale.getId());
}

/**
* Count words using Okapi's WordCounter, which tries to implement the LISA
* standard GMX-V:
* http://web.archive.org/web/20090403134742/http://www.lisa.org/Global
* -information-m.105.0.html
*
* @param s
* @param bcp47Locale
* @return
*/
public static long countWords(String s, String bcp47Locale)
{
try
Expand All @@ -62,9 +72,7 @@ public static long countWords(String s, String bcp47Locale)
catch (Exception e)
{
Object[] args = new Object[] {s, bcp47Locale, e};
if (log.isInfoEnabled())
log.info("unable to count words in string '{}' for locale '{}'", args);
log.error("unable to count words in string '{}' for locale '{}': {}", args);
log.error("unable to count words in string '{}' for locale '{}'", args);
return 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Test(groups = { "unit-tests" })
public class OkapiUtilTest
{
// @formatter:off
String[] strings =
{
"<author><firstname>Emmanuel</firstname> <surname>Bernard</surname></author>",
Expand All @@ -23,15 +24,23 @@ public class OkapiUtilTest
"\n" +
"// later, in a new session\n" +
"secondSession.saveOrUpdate(cat); // update existing state (cat has a non-null id)\n" +
"secondSession.saveOrUpdate(mate); // save the new instance (mate has a null id)"
"secondSession.saveOrUpdate(mate); // save the new instance (mate has a null id)",

"<filename class=\"directory\">/var/lib/ricci</filename>",

"https://cdn.redhat.com", // NB okapi says 2, but looks like 4. perhaps
// something.ext counts as one word?

"/etc/rhsm/rhsm.conf", // NB okapi says 3, but looks like 4
};
// @formatter:on
long[] count =
{
8,
2,
9,
// 4+8+7+4+3+5+11+12 = 54 ?
49
49, 7, 2, 3,
};
@Test
public void testCountWords()
Expand Down

0 comments on commit 882dfd7

Please sign in to comment.