/* The contents of this file are subject to the AMP Open Community License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License on the AMP web site (http://www.tibet.iteso.mx/Guatemala/). Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific terms governing rights and limitations under the License. The Initial Developer of this software is Andres Montano Pellegrini. Portions created by Andres Montano Pellegrini are Copyright 2001 Andres Montano Pellegrini. All Rights Reserved. Contributor(s): ______________________________________. */ package org.thdl.tib.scanner; /** Miscelaneous static methods for the manipulation of Tibetan text. @author Andrés Montano Pellegrini */ public class Manipulate { private static String endOfParagraphMarks = "/;|!:^@#$%="; private static String bracketMarks = "<>(){}[]"; private static String endOfSyllableMarks = " _\t"; private static String allStopMarkers = endOfSyllableMarks + endOfParagraphMarks + bracketMarks; /* public static String[] parseFields (String s, char delimiter) { int pos; String field; SimplifiedLinkedList ll = new SimplifiedLinkedList(); while ((pos = s.indexOf(delimiter))>=0) { field = s.substring(0, pos).trim(); ll.addLast(field); s = s.substring(pos+1); } ll.addLast(s.trim()); return ll.toStringArray(); }*/ public static int indexOfAnyChar(String str, String chars) { int i; for (i=0; i=0) return i; } return -1; } public static int indexOfExtendedEndOfSyllableMark(String word) { return indexOfAnyChar(word, allStopMarkers); } public static int indexOfBracketMarks(String word) { return indexOfAnyChar(word, bracketMarks); } public static boolean isPunctuationMark(int ch) { return endOfParagraphMarks.indexOf(ch)>=0 || bracketMarks.indexOf(ch)>=0; } public static boolean isEndOfParagraphMark(int ch) { return endOfParagraphMarks.indexOf(ch)>=0; } public static boolean isEndOfSyllableMark(int ch) { return endOfSyllableMarks.indexOf(ch)>=0; } public static boolean isMeaningful(String s) { for (int i=0; i10) n = 10; for (i=0; i=0xF00 && ch<=0xFFF; } public static boolean guessIfUnicode(String line) { char ch; int letters=0, unicode=0, i, n; n = line.length(); if (n>10) n = 10; for (i=0; i0) { switch (ch) { case 'r': case 'l': case 'w': i--; break; case 'y': ch2 = sil.charAt(i-1); switch (ch2) { case '.': return "y"; case 'n': return "ny"; default: i--; } } } if (i==0) return sil.substring(i,i+1); ch = sil.charAt(i); ch2 = sil.charAt(i-1); switch(ch) { case 'h': switch (ch2) { case 'k': case 'c': case 't': case 'p': case 'z': return sil.substring(i-1,i+1); case 's': if (i-2>=0 && sil.charAt(i-2)=='t') return "tsh"; else return "sh"; default: return "h"; } case 's': if (ch2=='t') return "ts"; else return "s"; case 'g': if (ch2=='n') return "ng"; else return "g"; case 'z': if (ch2=='d') return "dz"; else return "z"; } return sil.substring(i,i+1); } public static String deleteQuotes(String s) { int length = s.length(), pos; if (length>2) { if ((s.charAt(0)=='\"') && (s.charAt(length-1)=='\"')) s = s.substring(1,length-1); do { pos = s.indexOf("\"\""); if (pos<0) break; s = Manipulate.deleteSubstring(s, pos, pos+1); } while (true); } return s; } /** Syntax: java Manipulate [word-file] < source-dic-entries > dest-dic-entries Takes the output of ConsoleScannerFilter (in RY format), converts the Wylie to Acip and displays the result in csv format. arch-palabras es usado solo cuando deseamos las palabras cambiadas a otro archivo. public static void main (String[] args) throws Exception { String linea, palabra, definicion, nuevaPalabra; int marker; PrintWriter psPalabras = null; BufferedReader keyb = new BufferedReader(new InputStreamReader(System.in)); if (args.length==1) psPalabras = new PrintWriter(new FileOutputStream(args[0])); while ((linea=keyb.readLine())!=null) { if (linea.trim().equals("")) continue; marker = linea.indexOf('-'); if (marker<0) // linea tiene error { palabra = linea; definicion = ""; } else { palabra = linea.substring(0, marker).trim(); definicion = linea.substring(marker+1).trim(); } nuevaPalabra = wylieToAcip(palabra); if (psPalabras!=null) psPalabras.println(nuevaPalabra); else System.out.print(nuevaPalabra + '\t'); if (definicion.equals("")) System.out.println(palabra); else System.out.println(palabra + '\t' + definicion); } if (psPalabras!=null) psPalabras.flush(); }*/ /** From http://www.i18nfaq.com/2005/07/how-do-i-convert-ncr-format-to-java.html */ public static String NCR2UnicodeString(String str) { StringBuffer ostr = new StringBuffer(); int i1=0; int i2=0; while(i2