Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //:name=Word Count MS-Word style :description=
- import org.omegat.core.data.ProtectedPart
- console.println("Word Count MSWord\n");
- def total_source_word_count = 0;
- def total_target_word_count = 0;
- def files = project.projectFiles;
- for (i in 0 ..< files.size())
- {
- fi = files[i];
- def source_word_count = 0;
- def target_word_count = 0;
- console.println("== " + fi.filePath);
- for (j in 0 ..< fi.entries.size())
- {
- ste = fi.entries[j];
- source = ste.getSrcText();
- source_word_count += count_segment(source);
- if (project.getTranslationInfo(ste)) {
- def targ = project.getTranslationInfo(ste).translation
- if (targ == null) continue;
- for (ProtectedPart pp : ste.getProtectedParts()) {
- targ = targ.replace(pp.getTextInSourceSegment(), pp.getReplacementWordsCountCalculation())
- }
- target_word_count += count_segment(targ);
- }
- }
- total_source_word_count += source_word_count;
- total_target_word_count += target_word_count;
- console.println("Source\t" + source_word_count);
- console.println("Target\t" + target_word_count);
- console.println("");
- }
- console.println("==================================");
- console.println("Total");
- console.println("Source\t" + total_source_word_count);
- console.println("Target\t" + total_target_word_count);
- def count_segment (s) {
- if (s == null) return 0;
- def spaces = /[\u00a0|\p{Blank}|\p{Space}]+/;
- def w = s.trim().replaceAll(spaces, " ").split(spaces);
- def c = w.length;
- //console.print(Arrays.toString(w) + "\t" + c + "\n");
- return c;
- }
Add Comment
Please, Sign In to add comment