-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt at Chinese Simple CoreNLP
- Loading branch information
Gabor Angeli
authored and
Stanford NLP
committed
Jun 2, 2016
1 parent
b4ff3c7
commit adb5f3b
Showing
5 changed files
with
198 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package edu.stanford.nlp.simple; | ||
|
||
import edu.stanford.nlp.io.IOUtils; | ||
import edu.stanford.nlp.io.RuntimeIOException; | ||
import edu.stanford.nlp.pipeline.Annotation; | ||
import edu.stanford.nlp.pipeline.AnnotatorImplementations; | ||
import edu.stanford.nlp.pipeline.CoreNLPProtos; | ||
import edu.stanford.nlp.pipeline.StanfordCoreNLP; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
/** | ||
* A sentence running with the Chinese models. | ||
* | ||
* @author <a href="mailto:gabor@eloquent.ai">Gabor Angeli</a> | ||
*/ | ||
public class ChineseDocument extends Document { | ||
/** | ||
* An SLF4J Logger for this class. | ||
*/ | ||
private static final Logger log = LoggerFactory.getLogger(ChineseDocument.class); | ||
|
||
/** | ||
* The empty {@link java.util.Properties} object, for use with creating default annotators. | ||
*/ | ||
static final Properties EMPTY_PROPS = new Properties() {{ | ||
try { | ||
load(IOUtils.getInputStreamFromURLOrClasspathOrFileSystem("edu/stanford/nlp/pipeline/StanfordCoreNLP-chinese.properties")); | ||
} catch (IOException e) { | ||
throw new RuntimeIOException(e); | ||
} | ||
setProperty("language", "chinese"); | ||
setProperty("annotators", ""); | ||
}}; | ||
|
||
/** | ||
* Create a new document from the passed in text. | ||
* @param text The text of the document. | ||
*/ | ||
public ChineseDocument(String text) { | ||
super(ChineseDocument.EMPTY_PROPS, text); | ||
} | ||
|
||
/** | ||
* Convert a CoreNLP Annotation object to a Document. | ||
* @param ann The CoreNLP Annotation object. | ||
*/ | ||
@SuppressWarnings("Convert2streamapi") | ||
public ChineseDocument(Annotation ann) { | ||
super(ChineseDocument.EMPTY_PROPS, ann); | ||
} | ||
|
||
|
||
/** | ||
* Create a Document object from a read Protocol Buffer. | ||
* @see edu.stanford.nlp.simple.Document#serialize() | ||
* @param proto The protocol buffer representing this document. | ||
*/ | ||
public ChineseDocument(CoreNLPProtos.Document proto) { | ||
super(ChineseDocument.EMPTY_PROPS, proto); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package edu.stanford.nlp.simple; | ||
|
||
import edu.stanford.nlp.io.IOUtils; | ||
import edu.stanford.nlp.io.RuntimeIOException; | ||
import edu.stanford.nlp.pipeline.CoreNLPProtos; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
/** | ||
* A {@link Sentence}, but in Chinese. | ||
* | ||
* @author <a href="mailto:gabor@eloquent.ai">Gabor Angeli</a> | ||
*/ | ||
public class ChineseSentence extends Sentence { | ||
/** | ||
* An SLF4J Logger for this class. | ||
*/ | ||
private static final Logger log = LoggerFactory.getLogger(ChineseSentence.class); | ||
|
||
/** A properties object for creating a document from a single sentence. Used in the constructor {@link Sentence#Sentence(String)} */ | ||
static Properties SINGLE_SENTENCE_DOCUMENT = new Properties() {{ | ||
try { | ||
load(IOUtils.getInputStreamFromURLOrClasspathOrFileSystem("edu/stanford/nlp/pipeline/StanfordCoreNLP-chinese.properties")); | ||
} catch (IOException e) { | ||
throw new RuntimeIOException(e); | ||
} | ||
setProperty("language", "chinese"); | ||
setProperty("annotators", ""); | ||
setProperty("ssplit.isOneSentence", "true"); | ||
setProperty("tokenize.class", "PTBTokenizer"); | ||
setProperty("tokenize.language", "en"); | ||
}}; | ||
|
||
/** A properties object for creating a document from a single tokenized sentence. */ | ||
private static Properties SINGLE_SENTENCE_TOKENIZED_DOCUMENT = new Properties() {{ | ||
try { | ||
load(IOUtils.getInputStreamFromURLOrClasspathOrFileSystem("edu/stanford/nlp/pipeline/StanfordCoreNLP-chinese.properties")); | ||
} catch (IOException e) { | ||
throw new RuntimeIOException(e); | ||
} | ||
setProperty("language", "chinese"); | ||
setProperty("annotators", ""); | ||
setProperty("ssplit.isOneSentence", "true"); | ||
setProperty("tokenize.class", "WhitespaceTokenizer"); | ||
setProperty("tokenize.language", "en"); | ||
setProperty("tokenize.whitespace", "true"); // redundant? | ||
}}; | ||
|
||
public ChineseSentence(String text) { | ||
super(text, SINGLE_SENTENCE_DOCUMENT); | ||
} | ||
|
||
public ChineseSentence(List<String> tokens) { | ||
super(tokens, SINGLE_SENTENCE_TOKENIZED_DOCUMENT); | ||
} | ||
|
||
public ChineseSentence(CoreNLPProtos.Sentence proto) { | ||
super(proto, SINGLE_SENTENCE_DOCUMENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.