All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.trees.international.pennchinese.ChineseEscaper Maven / Gradle / Ivy

Go to download

Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.

There is a newer version: 4.5.7
Show newest version
package edu.stanford.nlp.trees.international.pennchinese; 
import edu.stanford.nlp.util.logging.Redwood;

import java.util.List;
import java.util.ArrayList;
import java.util.regex.*;

import edu.stanford.nlp.ling.HasWord;
import java.util.function.Function;
import edu.stanford.nlp.util.StringUtils;
import edu.stanford.nlp.util.UTF8EquivalenceFunction;

/**
 * An Escaper for Chinese normalization to match Treebank.
 * Currently normalizes "ASCII" characters into the full-width
 * range used inside the Penn Chinese Treebank.
 * 

* Notes: Smart quotes appear in CTB, and are left unchanged. * I think you get various hyphen types from U+2000 range too - certainly, * Roger lists them in LanguagePack. * * @author Christopher Manning */ public class ChineseEscaper implements Function, List> { /** A logger for this class */ private static Redwood.RedwoodChannels log = Redwood.channels(ChineseEscaper.class); /** IBM entity normalization patterns */ private static final Pattern p2 = Pattern.compile("\\$[a-z]+_\\((.*?)\\|\\|.*?\\)"); /** Note: At present this clobbers the input list items. * This should be fixed. */ public List apply(List arg) { List ans = new ArrayList<>(arg); for (HasWord wd : ans) { String w = wd.word(); Matcher m2 = p2.matcher(w); // log.info("Escaper: w is " + w); if (m2.find()) { // log.info(" Found pattern."); w = m2.replaceAll("$1"); // log.info(" Changed it to: " + w); } String newW = UTF8EquivalenceFunction.replaceAscii(w); wd.setWord(newW); } return ans; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy