Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
use NlpTools\Documents\TrainingSet;
use NlpTools\Documents\WordDocument;
class PosTrainingSet extends TrainingSet
* Read word-tag pairs from a file and create a TrainingSet.
* The file should have the following format
* <word> <space> <tag> <new line>
* @param string|Iterator $file The filename that contains the tagged words or an iterator returninthe above formatted lines
* @return PosTrainingSet The training set from the file
public static function fromFile($file, $context=1) {
if (!($file instanceof Iterator)) {
$file = new SplFileObject($file);
$lines = array_filter(
function ($line) {
return array_map("trim",explode(" ", $line));
iterator_to_array($file, false)
$words = array_map(
function ($l) {
return $l[0];
$tset = new PosTrainingSet();
foreach ($lines as $idx=>$l) {
if (count($l)<2)
$l[1], // the tag
new WordDocument(
return $tset;