• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java StringTools类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.languagetool.tools.StringTools的典型用法代码示例。如果您正苦于以下问题:Java StringTools类的具体用法?Java StringTools怎么用?Java StringTools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

StringTools类属于org.languagetool.tools包,在下文中一共展示了StringTools类的35个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loadFile

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
void loadFile() {
	final File file = Tools
			.openFileDialog(frame, new PlainTextFileFilter());
	if (file == null) {
		// user clicked cancel
		return;
	}
	try {
		final String fileContents = StringTools
				.readFile(new FileInputStream(file.getAbsolutePath()));
		textArea.setText(fileContents);
		checkTextAndDisplayResults();
	} catch (final IOException e) {
		Tools.showError(e);
	}
}
 

开发者ID:markkohdev,
项目名称:oStorybook,
代码行数:17,
代码来源:LangToolMain.java

示例2: makePopupMenu

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private PopupMenu makePopupMenu() {
	final PopupMenu popup = new PopupMenu();
	final ActionListener rmbListener = new TrayActionRMBListener();
	// Check clipboard text:
	final MenuItem checkClipboardItem = new MenuItem(
			StringTools.getLabel(messages
					.getString("guiMenuCheckClipboard")));
	checkClipboardItem.addActionListener(rmbListener);
	popup.add(checkClipboardItem);
	// Open main window:
	final MenuItem restoreItem = new MenuItem(StringTools.getLabel(messages
			.getString("guiMenuShowMainWindow")));
	restoreItem.addActionListener(rmbListener);
	popup.add(restoreItem);
	// Exit:
	final MenuItem exitItem = new MenuItem(StringTools.getLabel(messages
			.getString("guiMenuQuit")));
	exitItem.addActionListener(rmbListener);
	popup.add(exitItem);
	return popup;
}
 

开发者ID:markkohdev,
项目名称:oStorybook,
代码行数:22,
代码来源:LangToolMain.java

示例3: actionPerformed

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
	if (e.getActionCommand().equalsIgnoreCase(
			StringTools.getLabel(messages
					.getString("guiMenuCheckClipboard")))) {
		restoreFromTrayAndCheck();
	} else if (e.getActionCommand().equalsIgnoreCase(
			StringTools.getLabel(messages
					.getString("guiMenuShowMainWindow")))) {
		restoreFromTray();
	} else if (e.getActionCommand().equalsIgnoreCase(
			StringTools.getLabel(messages.getString("guiMenuQuit")))) {
		quit();
	} else {
		JOptionPane.showMessageDialog(null,
				"Unknown action: " + e.getActionCommand(), "Error",
				JOptionPane.ERROR_MESSAGE);
	}
}
 

开发者ID:markkohdev,
项目名称:oStorybook,
代码行数:20,
代码来源:LangToolMain.java

示例4: initStrings

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private void initStrings() {
  fileMenu = new JMenu(StringTools.getLabel(
      messages.getString("guiMenuFile")));
  helpMenu = new JMenu(StringTools.getLabel(
      messages.getString("guiMenuHelp")));
  // File:
  openText = StringTools.getLabel(
      messages.getString("guiMenuOpen"));
  checkClipboardText = StringTools.getLabel(
      messages.getString("guiMenuCheckClipboard"));
  dockToTrayText = StringTools.getLabel(
      messages.getString("guiMenuHide"));
  addLanguageText = StringTools.getLabel(
      messages.getString("guiMenuAddRules"));
  tagText = StringTools.getLabel(
          messages.getString("guiTagText"));
  optionsText = StringTools.getLabel(
      messages.getString("guiMenuOptions"));
  quitText = StringTools.getLabel(
      messages.getString("guiMenuQuit"));
  // Help:
  aboutText = StringTools.getLabel(
      messages.getString("guiMenuAbout"));
}
 

开发者ID:markkohdev,
项目名称:oStorybook,
代码行数:25,
代码来源:MainMenuBar.java

示例5: tagText

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private void tagText() {
  if (StringTools.isEmpty(textArea.getText().trim())) {
    textArea.setText(messages.getString("enterText2"));
    return;
  }
  setWaitCursor();
  new Thread() {
    @Override
    public void run() {
      try {
        tagTextAndDisplayResults();
      } finally {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            unsetWaitCursor();
          }
        });
      }
    }
  }.start();
}
 

开发者ID:thamizha,
项目名称:thamizha-ilakkanam,
代码行数:23,
代码来源:Main.java

示例6: getClipboardText

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private String getClipboardText() {
  // get text from clipboard or selection:
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
  if (clipboard == null) { // on Windows
    clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  }
  String s;
  final Transferable data = clipboard.getContents(this);
  try {
    if (data != null
        && data.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) {
      final DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
      final Reader sr = df.getReaderForText(data);
      s = StringTools.readerToString(sr);
    } else {
      s = "";
    }
  } catch (Exception ex) {
    if (data != null) {
      s = data.toString();
    } else {
      s = "";
    }
  }
  return s;
}
 

开发者ID:thamizha,
项目名称:thamizha-ilakkanam,
代码行数:27,
代码来源:Main.java

示例7: loadMapping

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private MappingAndTags loadMapping(InputStream inputStream, String encoding) throws IOException {
  MappingAndTags result = new MappingAndTags();
  try (Scanner scanner = new Scanner(inputStream, encoding)) {
    while (scanner.hasNextLine()) {
      String line = scanner.nextLine();
      if (StringTools.isEmpty(line) || line.charAt(0) == '#') {
        continue;
      }
      String[] parts = line.split("\t");
      if (parts.length != 3) {
        throw new IOException("Unknown line format when loading manual synthesizer dictionary: " + line);
      }
      String key = parts[1] + "|" + parts[2];
      if (!result.mapping.containsKey(key)) {
        result.mapping.put(key, new ArrayList<>());
      }
      result.mapping.get(key).add(parts[0]);
      result.tags.add(parts[2]); // POS
    }
  }
  return result;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:23,
代码来源:ManualSynthesizer.java

示例8: urlEndsAt

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private boolean urlEndsAt(int i, List<String> l, String urlQuote) {
  String token = l.get(i);
  if (StringTools.isWhitespace(token)) {
    return true;
  } else if (token.equals(")") || token.equals("]")) {   // this is guesswork
    return true;
  } else if (l.size() > i + 1) {
    String nToken = l.get(i + 1);
    if (StringTools.isWhitespace(nToken) &&
          (StringUtils.equalsAny(token, ".", ",", ";", ":", "!", "?") || token.equals(urlQuote))) {
      return true;
    }
  } else {
    Matcher matcher = URL_CHARS.matcher(token);
    if (!matcher.matches()) {
      return true;
    }
  }
  return false;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:21,
代码来源:WordTokenizer.java

示例9: loadMapping

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private Map<String, List<TaggedWord>> loadMapping(InputStream inputStream, String encoding) throws IOException {
  Map<String, List<TaggedWord>> map = new HashMap<>();
  try (
    InputStreamReader reader = new InputStreamReader(inputStream, encoding);
    BufferedReader br = new BufferedReader(reader)
  ) {
    String line;
    while ((line = br.readLine()) != null) {
      if (StringTools.isEmpty(line) || line.charAt(0) == '#') {
        continue;
      }
      String[] parts = line.split("\t");
      if (parts.length != 3) {
        throw new IOException("Unknown line format when loading manual tagger dictionary, expected three tab-separated fields: '" + line + "'");
      }
      List<TaggedWord> terms = map.get(parts[0]);
      if (terms == null) {
        terms = new ArrayList<>();
      }
      terms.add(new TaggedWord(parts[1], parts[2].trim()));
      map.put(parts[0], terms);
    }
  }
  return map;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:26,
代码来源:ManualTagger.java

示例10: finalizeExceptions

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
protected void finalizeExceptions() {
  inException = false;
  if (!exceptionSet) {
    boolean tokenCase = caseSensitive;
    if (tokenLevelCaseSet) {
      tokenCase = tokenLevelCaseSensitive;
    }
    patternToken = new PatternToken(elements.toString(), tokenCase, regExpression, tokenInflected);
    exceptionSet = true;
  }
  patternToken.setNegation(tokenNegated);
  if (!StringTools.isEmpty(exceptions.toString()) || exceptionPosToken != null) {
    patternToken.setStringPosException(exceptions.toString(), exceptionStringRegExp,
        exceptionStringInflected, exceptionStringNegation, exceptionValidNext, exceptionValidPrev,
        exceptionPosToken, exceptionPosRegExp, exceptionPosNegation, exceptionLevelCaseSensitive);
    exceptionPosToken = null;
    exceptionLevelCaseSensitive = null;
  }
  if (exceptionSpaceBeforeSet) {
    patternToken.setExceptionSpaceBefore(exceptionSpaceBefore);
  }
  resetException();
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:24,
代码来源:XMLRuleHandler.java

示例11: combineLists

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
/**
 * Creates a Cartesian product of the arrays stored in the input array.
 * @param input Array of string arrays to combine.
 * @param output Work array of strings.
 * @param r Starting parameter (use 0 to get all combinations).
 * @param lang Text language for adding spaces in some languages.
 * @return Combined array of String.
 */
private static String[] combineLists(String[][] input,
    String[] output, int r, Language lang) {
  List<String> outputList = new ArrayList<>();
  if (r == input.length) {
    StringBuilder sb = new StringBuilder();
    for (int k = 0; k < output.length; k++) {
      sb.append(output[k]);
      if (k < output.length - 1) {
        sb.append(StringTools.addSpace(output[k + 1], lang));
      }
    }
    outputList.add(sb.toString());
  } else {
    for (int c = 0; c < input[r].length; c++) {
      output[r] = input[r][c];
      String[] sList = combineLists(input, output, r + 1, lang);
      outputList.addAll(Arrays.asList(sList));
    }
  }
  return outputList.toArray(new String[outputList.size()]);
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:30,
代码来源:PatternRuleMatcher.java

示例12: setStringElement

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
public void setStringElement(String token) {
  if (token != null) {
    stringToken = StringTools.trimWhitespace(token);
  } else {
    stringToken = null;
  }
  testString = !StringTools.isEmpty(stringToken);
  if (testString && stringRegExp) {
    String regToken = stringToken;
    if (!caseSensitive) {
      regToken = CASE_INSENSITIVE + stringToken;
    }
    if (!"\\0".equals(token)) {
      pattern = Pattern.compile(regToken);
    }
  }
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:18,
代码来源:PatternToken.java

示例13: doCompile

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private void doCompile(AnalyzedTokenReadings token, Synthesizer synth) throws IOException {
  MatchState matchState = tokenReference.createState(synth, token);
  if (StringTools.isEmpty(referenceString)) {
    referenceString = stringToken;
  }
  String reference = "\\" + tokenReference.getTokenRef();
  if (tokenReference.setsPos()) {
    String posReference = matchState.getTargetPosTag();
    if (posReference != null) {
      setPosToken(new PosToken(posReference, tokenReference.posRegExp(), negation));
    }
    setStringElement(referenceString.replace(reference, ""));
  } else {
    setStringElement(referenceString.replace(reference, matchState.toTokenString()));
  }
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:17,
代码来源:PatternToken.java

示例14: getPasswordAuthentication

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
@Override
@Nullable
protected PasswordAuthentication getPasswordAuthentication() {
  if (getRequestingURL() == null) {
    return null;
  }
  String userInfo = getRequestingURL().getUserInfo();
  if (StringTools.isEmpty(userInfo)) {
    return null;
  }
  String[] parts = userInfo.split(":");
  if (parts.length != 2) {
    throw new RuntimeException("Invalid userInfo format, expected 'user:password': " + userInfo);
  }
  String username = parts[0];
  String password = parts[1];
  return new PasswordAuthentication(username, password.toCharArray());
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:19,
代码来源:PasswordAuthenticator.java

示例15: getNewToken

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private List<AnalyzedToken> getNewToken(int numRead, String token) {
  String posTag = match.getPosTag();
  List<AnalyzedToken> list = new ArrayList<>();
  String lemma = "";
  for (int j = 0; j < numRead; j++) {
    String tempPosTag = formattedToken.getAnalyzedToken(j).getPOSTag();
    if (tempPosTag != null) {
      if (tempPosTag.equals(posTag) && formattedToken.getAnalyzedToken(j).getLemma() != null) {
        lemma = formattedToken.getAnalyzedToken(j).getLemma();
      }
      if (StringTools.isEmpty(lemma)) {
        lemma = formattedToken.getAnalyzedToken(0).getLemma();
      }
      list.add(new AnalyzedToken(token, posTag, lemma));
      list.get(list.size() - 1).setWhitespaceBefore(
          formattedToken.isWhitespaceBefore());
    }
  }
  return list;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:21,
代码来源:MatchState.java

示例16: RuleMatch

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
/**
 * Creates a RuleMatch object, taking the rule that triggered
 * this match, position of the match and an explanation message.
 * This message is scanned for &lt;suggestion&gt;...&lt;/suggestion&gt;
 * to get suggested fixes for the problem detected by this rule. 
 * 
 * @param fromPos error start position in original text
 * @param toPos error end position in original text
 * @param shortMessage used for example in OpenOffice/LibreOffice's context menu (may be null)
 * @param startWithUppercase whether the original text at the position
 *    of the match starts with an uppercase character
 * @since 4.0
 */
public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message, String shortMessage, 
    boolean startWithUppercase, String suggestionsOutMsg) {
  this.rule = Objects.requireNonNull(rule);
  if (toPos <= fromPos) {
    throw new RuntimeException("fromPos (" + fromPos + ") must be less than toPos (" + toPos + ")");
  }
  this.offsetPosition = new OffsetPosition(fromPos, toPos);
  this.message = Objects.requireNonNull(message);
  this.shortMessage = shortMessage;
  // extract suggestion from <suggestion>...</suggestion> in message:
  Matcher matcher = SUGGESTION_PATTERN.matcher(message + suggestionsOutMsg);
  int pos = 0;
  while (matcher.find(pos)) {
    pos = matcher.end();
    String replacement = matcher.group(1);
    if (startWithUppercase) {
      replacement = StringTools.uppercaseFirstChar(replacement);
    }
    if (!suggestedReplacements.contains(replacement)) {
      suggestedReplacements.add(replacement);
    }
  }
  this.sentence = sentence;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:38,
代码来源:RuleMatch.java

示例17: createRuleMatch

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
protected RuleMatch createRuleMatch(AnalyzedTokenReadings tokenReadings,
                                    List<String> replacements, AnalyzedSentence sentence) {
  String tokenString = tokenReadings.getToken();
  int pos = tokenReadings.getStartPos();

  RuleMatch potentialRuleMatch = new RuleMatch(this, sentence, pos, pos
      + tokenString.length(), getMessage(tokenString, replacements), getShort());

  if (!isCaseSensitive() && StringTools.startsWithUppercase(tokenString)) {
    for (int i = 0; i < replacements.size(); i++) {
      replacements.set(i, StringTools.uppercaseFirstChar(replacements.get(i)));
    }
  }

  potentialRuleMatch.setSuggestedReplacements(replacements);

  return potentialRuleMatch;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:19,
代码来源:AbstractSimpleReplaceRule.java

示例18: getGoogleTokens

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
@Experimental
static List<GoogleToken> getGoogleTokens(AnalyzedSentence sentence, boolean addStartToken, Tokenizer wordTokenizer) {
  List<GoogleToken> result = new ArrayList<>();
  if (addStartToken) {
    result.add(new GoogleToken(LanguageModel.GOOGLE_SENTENCE_START, 0, 0));
  }
  List<String> tokens = wordTokenizer.tokenize(sentence.getText());
  int startPos = 0;
  for (String token : tokens) {
    if (!StringTools.isWhitespace(token)) {
      int endPos = startPos + token.length();
      Set<AnalyzedToken> pos = findOriginalAnalyzedTokens(sentence, startPos, endPos);
      GoogleToken gToken = new GoogleToken(token, startPos, endPos, pos);
      result.add(gToken);
    }
    startPos += token.length();
  }
  return result;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:20,
代码来源:GoogleToken.java

示例19: acceptPhrases

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
/**
 * Accept (case-sensitively, unless at the start of a sentence) the given phrases even though they
 * are not in the built-in dictionary.
 * Use this to avoid false alarms on e.g. names and technical terms. Unlike {@link #addIgnoreTokens(List)}
 * this can deal with phrases. A way to call this is like this:
 * <code>rule.acceptPhrases(Arrays.asList("duodenal atresia"))</code>
 * This way, checking would not create an error for "duodenal atresia", but it would still
 * create and error for "duodenal" or "atresia" if they appear on their own.
 * @since 3.3
 */
public void acceptPhrases(List<String> phrases) {
  List<List<PatternToken>> antiPatterns = new ArrayList<>();
  for (String phrase : phrases) {
    String[] parts = phrase.split(" ");
    List<PatternToken> patternTokens = new ArrayList<>();
    int i = 0;
    boolean startsLowercase = false;
    for (String part : parts) {
      if (i == 0) {
        String uppercased = StringTools.uppercaseFirstChar(part);
        if (!uppercased.equals(part)) {
          startsLowercase = true;
        }
      }
      patternTokens.add(new PatternTokenBuilder().csToken(part).build());
      i++;
    }
    antiPatterns.add(patternTokens);
    if (startsLowercase) {
      antiPatterns.add(getTokensForSentenceStart(parts));
    }
  }
  this.antiPatterns = makeAntiPatterns(antiPatterns, language);
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:35,
代码来源:SpellingCheckRule.java

示例20: getTokensForSentenceStart

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private List<PatternToken> getTokensForSentenceStart(String[] parts) {
  List<PatternToken> ucPatternTokens = new ArrayList<>();
  int j = 0;
  for (String part : parts) {
    if (j == 0) {
      // at sentence start, we also need to accept a phrase that starts with an uppercase char:
      String uppercased = StringTools.uppercaseFirstChar(part);
      ucPatternTokens.add(new PatternTokenBuilder().posRegex(JLanguageTool.SENTENCE_START_TAGNAME).build());
      ucPatternTokens.add(new PatternTokenBuilder().csToken(uppercased).build());
    } else {
      ucPatternTokens.add(new PatternTokenBuilder().csToken(part).build());
    }
    j++;
  }
  return ucPatternTokens;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:17,
代码来源:SpellingCheckRule.java

示例21: tagText

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private void tagText() {
  if (StringTools.isEmpty(textArea.getText().trim())) {
    textArea.setText(messages.getString("enterText2"));
    return;
  }
  setWaitCursor();
  new Thread() {
    @Override
    public void run() {
      try {
        tagTextAndDisplayResults();
      } finally {
        SwingUtilities.invokeLater(() -> unsetWaitCursor());
      }
    }
  }.start();
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:18,
代码来源:Main.java

示例22: getClipboardText

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private String getClipboardText() {
  // get text from clipboard or selection:
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
  if (clipboard == null) { // on Windows
    clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  }
  String s;
  Transferable data = clipboard.getContents(this);
  try {
    if (data != null
            && data.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) {
      DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
      try (Reader sr = df.getReaderForText(data)) {
        s = StringTools.readerToString(sr);
      }
    } else {
      s = "";
    }
  } catch (Exception ex) {
    s = data.toString();
  }
  return s;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:24,
代码来源:Main.java

示例23: testTranslationsAreNotEmpty

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
@Test
public void testTranslationsAreNotEmpty() throws IOException {
  for (Language lang : Languages.get()) {
    File file1 = getTranslationFile(lang);
    File file2 = getTranslationFileWithVariant(lang);
    if (!file1.exists() && !file2.exists()) {
      System.err.println("Note: no translation available for " + lang);
      continue;
    }
    File file = file1.exists() ? file1 : file2;
    List<String> lines = loadFile(file);
    for (String line : lines) {
      line = line.trim();
      if (StringTools.isEmpty(line) || line.charAt(0)=='#') {
        continue;
      }
      String[] parts = line.split("=");
      if (parts.length < 2) {
        System.err.println("***** Empty translation: '" + line + "' in file " + file);
        //fail("Empty translation: '" + line + "' in file " + file);
      }
    }
  }
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:25,
代码来源:TranslationTest.java

示例24: getCompoundForms

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
@NotNull
private String[] getCompoundForms(AnalyzedToken token, String posTag, boolean posTagRegExp) throws IOException {
  List<String> parts = splitter.tokenize(token.getToken());
  String firstPart = String.join("", parts.subList(0, parts.size() - 1));
  String lastPart = StringTools.uppercaseFirstChar(parts.get(parts.size() - 1));
  AnalyzedToken lastPartToken = new AnalyzedToken(lastPart, posTag, lastPart);
  String[] lastPartForms;
  if (posTagRegExp) {
    lastPartForms = super.synthesize(lastPartToken, posTag, true);
  } else {
    lastPartForms = super.synthesize(lastPartToken, posTag);
  }
  Set<String> results = new LinkedHashSet<>();  // avoid dupes
  for (String part : lastPartForms) {
    results.add(firstPart + StringTools.lowercaseFirstChar(part));
  }
  return results.toArray(new String[results.size()]);
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:19,
代码来源:GermanSynthesizer.java

示例25: checkAtUrlByPost

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
static String checkAtUrlByPost(URL url, String postData) throws IOException {
  String keepAlive = System.getProperty("http.keepAlive");
  try {
    System.setProperty("http.keepAlive", "false");  // without this, there's an overhead of about 1 second - not sure why
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);
    try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream())) {
      writer.write(postData);
      writer.flush();
      return StringTools.streamToString(connection.getInputStream(), "UTF-8");
    }
  } finally {
    if (keepAlive != null) {
      System.setProperty("http.keepAlive", keepAlive);
    }
  }
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:18,
代码来源:HTTPTools.java

示例26: verbAtSentenceStart

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private boolean verbAtSentenceStart(AnalyzedTokenReadings readings) throws IOException {
  // start of sentence is mis-tagged because of the uppercase first character, work around that:
  String lowercased = StringTools.lowercaseFirstChar(readings.getToken());
  List<AnalyzedTokenReadings> lcReadings = language.getTagger().tag(Collections.singletonList(lowercased));
  if (lcReadings.size() > 0 && lcReadings.get(0).hasPartialPosTag("VER")) {
    return true;
  }
  // our dictionary doesn't know some imperative forms like "erzähl", but it knows "erzähle", so let's try that:
  if (!lowercased.endsWith("e")) {
    List<AnalyzedTokenReadings> lcImperativeReadings = language.getTagger().tag(Collections.singletonList(lowercased + "e"));
    if (lcImperativeReadings.size() > 0 && lcImperativeReadings.get(0).hasPartialPosTag("VER")) {
      return true;
    }
  }
  return false;
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:17,
代码来源:MissingVerbRule.java

示例27: run

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private void run() throws IOException {
  final Dictionary dictionary = Dictionary.read(
          JLanguageTool.getDataBroker().getFromResourceDirAsUrl("/de/german.dict"));
  final DictionaryLookup dl = new DictionaryLookup(dictionary);
  Tagger tagger = new German().getTagger();
  String prev = null;
  for (WordData wd : dl) {
    String word = wd.getWord().toString();
    if (word.endsWith("er") && StringTools.startsWithUppercase(word)) {
      if (!hasAdjReading(tagger, word) && isEigenname(tagger, word.substring(0, word.length()-2)) && !word.equals(prev)) {
        for (String newTags : ADJ_READINGS) {
          System.out.println(word + "\t" + word + "\t" + newTags + ":DEF");
          System.out.println(word + "\t" + word + "\t" + newTags + ":IND");
          System.out.println(word + "\t" + word + "\t" + newTags + ":SOL");
        }
        prev = word;
      }
    }
  }
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:21,
代码来源:GermanTaggerEnhancer.java

示例28: getActivityFor

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
int getActivityFor(Language lang, int pastDays) {
  try {
    Calendar past = GregorianCalendar.getInstance();
    past.add(Calendar.DAY_OF_MONTH, -pastDays);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String pastString = dateFormat.format(past.getTime());
    String langCode = lang.getShortCode();
    List<File> xmlFiles = getAllXmlFiles(lang, langCode);
    int commits = 0;
    for (File file : xmlFiles) {
      if (!file.exists()) {
        throw new RuntimeException("Not found: " + file);
      }
      String command = "git log --after=" + pastString + " " + file;
      Runtime runtime = Runtime.getRuntime();
      Process process = runtime.exec(command);
      InputStream inputStream = process.getInputStream();
      String output = StringTools.readStream(inputStream, "utf-8");
      process.waitFor();
      commits += getCommits(output);
    }
    return commits;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:27,
代码来源:RuleActivityOverview.java

示例29: getMaintainerInfo

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private String getMaintainerInfo(Language lang) {
  final StringBuilder maintainerInfo = new StringBuilder();
  if (lang.getMaintainers() != null) {
    for (Contributor contributor : lang.getMaintainers()) {
      if (!StringTools.isEmpty(maintainerInfo.toString())) {
        maintainerInfo.append(", ");
      }
      if (contributor.getUrl() != null) {
        maintainerInfo.append("<a href=\"");
        maintainerInfo.append(contributor.getUrl());
        maintainerInfo.append("\">");
      }
      maintainerInfo.append(contributor.getName());
      if (contributor.getUrl() != null) {
        maintainerInfo.append("</a>");
      }
    }
  }
  return maintainerInfo.toString();
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:21,
代码来源:RuleOverview.java

示例30: run

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private void run(final File file) throws IOException {
  if (file.isDirectory()) {
    final File[] files = file.listFiles();
    for (File file1 : files) {
      run(new File(file, file1.getName()));
    }
  } else {
    System.out.println("Checking " + file.getAbsolutePath());
    String text = StringTools.readStream(new FileInputStream(file.getAbsolutePath()), "utf-8");
    text = textFilter.filter(text);
    if (CHECK_BY_SENTENCE) {
      final Tokenizer sentenceTokenizer = langTool.getLanguage().getSentenceTokenizer();
      final List<String> sentences = sentenceTokenizer.tokenize(text);
      for (String sentence : sentences) {
        CommandLineTools.checkText(sentence, langTool, false, false, 1000);
      }
    } else {
      CommandLineTools.checkText(text, langTool);
    }
  }
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:22,
代码来源:CheckBNC.java

示例31: checkParams

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
@Override
protected void checkParams(Map<String, String> parameters) {
  super.checkParams(parameters);
  if (StringTools.isEmpty(parameters.get("language"))) {
    throw new IllegalArgumentException("Missing 'language' parameter, e.g. 'language=en-US' for American English or 'language=fr' for French");
  }
  if (parameters.get("enabled") != null) {
    throw new IllegalArgumentException("You specified 'enabled' but the parameter is now called 'enabledRules' in v2 of the API");
  }
  if (parameters.get("disabled") != null) {
    throw new IllegalArgumentException("You specified 'disabled' but the parameter is now called 'disabledRules' in v2 of the API");
  }
  if (parameters.get("preferredvariants") != null) {
    throw new IllegalArgumentException("You specified 'preferredvariants' but the parameter is now called 'preferredVariants' (uppercase 'V') in v2 of the API");
  }
  if (parameters.get("autodetect") != null) {
    throw new IllegalArgumentException("You specified 'autodetect' but automatic language detection is now activated with 'language=auto' in v2 of the API");
  }
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:20,
代码来源:V2TextChecker.java

示例32: testHTTPServer

点赞 3

import org.languagetool.tools.StringTools; //导入依赖的package包/类
@Test
@Override
public void testHTTPServer() throws Exception {
  File dir = new File(DATA_PATH);
  List<Language> languages = new ArrayList<>();
  //languages.add(new German());
  languages.addAll(Languages.get());
  for (Language language : languages) {
    File file = new File(dir, "tatoeba-" + language.getShortCode() + ".txt");
    if (!file.exists()) {
      System.err.println("No data found for " + language + ", language will not be tested");
    } else {
      String content = StringTools.readerToString(new FileReader(file));
      langCodeToText.put(language, content);
      System.err.println("Using " + content.length() + " bytes of data for " + language);
    }
  }
  if (langCodeToText.size() == 0) {
    throw new RuntimeException("No input data found in " + dir);
  }
  System.out.println("Testing " + langCodeToText.keySet().size() + " languages and variants");
  //super.testHTTPServer();  // start server in this JVM
  super.doTest();  // assume server has been started manually in its own JVM
}
 

开发者ID:languagetool-org,
项目名称:languagetool,
代码行数:25,
代码来源:HTTPServerMultiLangLoadTest.java

示例33: addListToProperties

点赞 2

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private void addListToProperties(Properties props, String key, Set<String> list) {
if (list == null) {
    props.setProperty(key, "");
} else {
    props.setProperty(key, StringTools.listToString(list, DELIMITER));
}
   }
 

开发者ID:markkohdev,
项目名称:oStorybook,
代码行数:8,
代码来源:Configuration.java

示例34: getClipboardText

点赞 2

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private String getClipboardText() {
	// get text from clipboard or selection:
	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
	if (clipboard == null) { // on Windows
		clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	}
	String s;
	final Transferable data = clipboard.getContents(this);
	try {
		if (data != null
				&& data.isDataFlavorSupported(DataFlavor
						.getTextPlainUnicodeFlavor())) {
			final DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
			final Reader sr = df.getReaderForText(data);
			s = StringTools.readerToString(sr);
		} else {
			s = "";
		}
	} catch (final Exception ex) {
		if (data != null) {
			s = data.toString();
		} else {
			s = "";
		}
	}
	return s;
}
 

开发者ID:markkohdev,
项目名称:oStorybook,
代码行数:28,
代码来源:LangToolMain.java

示例35: tagTextAndDisplayResults

点赞 2

import org.languagetool.tools.StringTools; //导入依赖的package包/类
private void tagTextAndDisplayResults(final JLanguageTool langTool) {
	if (StringTools.isEmpty(textArea.getText().trim())) {
		textArea.setText(messages.getString("enterText2"));
	} else {
		// tag text
		final List<String> sentences = langTool.sentenceTokenize(textArea
				.getText());
		final StringBuilder sb = new StringBuilder();
		try {
			for (String sent : sentences) {
				final AnalyzedSentence analyzedText = langTool
						.getAnalyzedSentence(sent);
				// final String analyzedTextString =
				// StringTools.escapeHTML(analyzedText.toString(", ")).
				// replace("[", "<font color='#888888'>[").replace("]",
				// "]</font>");
				final String analyzedTextString = StringTools
						.escapeHTML(analyzedText.toString())
						.replace("[", "<font color='#888888'>[")
						.replace("]", "]</font>");
				sb.append(analyzedTextString);
				sb.append("\n");
			}
		} catch (IOException e) {
			sb.append("An error occurred while tagging the text: "
					+ e.getMessage());
		}
		resultArea.setText(HTML_FONT_START + sb.toString() + HTML_FONT_END);
	}
}
 

开发者ID:markkohdev,
项目名称:oStorybook,
代码行数:31,
代码来源:LangToolMain.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)