示例#1
0
 /**
  * Reads parse trees either from standard input or a specified file, converting them to sentences
  * and printing those sentences on standard output.
  *
  * <pre>
  * usage: [-v|-help|-usage] [-tags] [filename]
  *         -v|-help|-usage: prints out this message
  *         -tags: indicates to spit out one S-expression per word, of the form
  *                 (word (tag))
  *         filename is the file to be processed (standard input is assumed if
  *                 this argument is "-" or is not present)
  * </pre>
  */
 public static void main(String[] args) {
   InputStream inStream = System.in;
   boolean tags = false;
   String inFile = null;
   for (int i = 0; i < args.length; i++) {
     if (args[i].equals("-help") || args[i].equals("-usage") || args[i].equals("-v")) {
       usage();
       return;
     } else if (args[i].equals("-tags")) tags = true;
     else if (!args[i].equals("-")) inFile = args[i];
   }
   if (inFile != null) {
     try {
       inStream = new FileInputStream(inFile);
     } catch (FileNotFoundException fnfe) {
       System.err.println(fnfe);
       System.exit(-1);
     }
   }
   try {
     SexpTokenizer tok = new SexpTokenizer(inStream, Language.encoding(), bufSize);
     OutputStream os = System.out;
     Writer writer = new BufferedWriter(new OutputStreamWriter(os, Language.encoding()));
     PrintWriter pw = new PrintWriter(writer);
     Sexp curr = null;
     while ((curr = Sexp.read(tok)) != null)
       pw.println(tags ? Util.collectTaggedWords(curr) : Util.collectLeaves(curr));
     pw.flush();
     pw.close();
   } catch (Exception e) {
     System.out.println(e);
   }
 }
示例#2
0
  public String getText(String key, String localeString) {
    String[] codes = localeString.toLowerCase().split("_");

    String languageCode = codes[0];

    if (!languages.containsKey(languageCode)) {
      languages.put(languageCode, new Language(languageCode));
    }

    Language language = languages.get(languageCode);

    if (codes.length >= 2) {
      return Colorizer.setColors(language.translate(key, codes[1]));
    }
    return Colorizer.setColors(language.translate(key));
  }
示例#3
0
  private AppContext(
      String root, File rootFile, String name, String environment, AppContext nonAdminParent) {
    super(name + ":" + environment);
    if (root == null) throw new NullPointerException("AppContext root can't be null");

    if (rootFile == null) throw new NullPointerException("AppContext rootFile can't be null");

    if (name == null) name = guessNameAndEnv(root).name;

    if (name == null) throw new NullPointerException("how could name be null");

    _root = root;
    _rootFile = rootFile;
    _git = new GitDir(_rootFile);
    _name = name;

    _environment = environment;
    _nonAdminParent = nonAdminParent;
    _admin = _nonAdminParent != null;
    _codePrefix = _admin ? "/~~/modules/admin/" : "";
    _moduleRegistry = ModuleRegistry.getNewGlobalChild();

    if (_git.isValid()) {
      _gitBranch = _git.getBranchOrTagName();
      _gitHash = _git.getCurrentHash();
    }

    _isGrid = name.equals("grid");

    _scope =
        new Scope(
            "AppContext:" + root + (_admin ? ":admin" : ""),
            _isGrid ? ed.cloud.Cloud.getInstance().getScope() : Scope.newGlobal(),
            null,
            Language.JS(),
            _rootFile);
    _scope.setGlobal(true);
    _initScope = _scope.child("_init");

    _usage = new UsageTracker(this);

    _baseScopeInit();

    _adminContext = _admin ? null : new AppContext(root, rootFile, name, environment, this);

    _rootContextReachable = new SeenPath();

    if (!_admin)
      _logger.info(
          "Started Context.  root:"
              + _root
              + " environment:"
              + environment
              + " git branch: "
              + _gitBranch);
  }
 @Nullable
 private static MorfologikMultiSpeller getSpeller(Language language) {
   if (!language.getShortName().equals(Locale.GERMAN.getLanguage())) {
     throw new RuntimeException("Language is not a variant of German: " + language);
   }
   try {
     String morfoFile = "/de/hunspell/de_" + language.getCountries()[0] + ".dict";
     if (JLanguageTool.getDataBroker().resourceExists(morfoFile)) {
       // spell data will not exist in LibreOffice/OpenOffice context
       try (InputStream stream =
               JLanguageTool.getDataBroker()
                   .getFromResourceDirAsStream("/de/hunspell/spelling.txt");
           BufferedReader br = new BufferedReader(new InputStreamReader(stream, "utf-8"))) {
         return new MorfologikMultiSpeller(morfoFile, new ExpandingReader(br), MAX_EDIT_DISTANCE);
       }
     } else {
       return null;
     }
   } catch (IOException e) {
     throw new RuntimeException("Could not set up morfologik spell checker", e);
   }
 }