Пример #1
0
 public function testStopwords()
 {
     $stopwords = new StopWords(array("to", "the"));
     $doc = new TokensDocument(explode(" ", "if you tell the truth you do not have to remember anything"));
     $doc->applyTransformation($stopwords);
     $this->assertEquals(array("if", "you", "tell", "truth", "you", "do", "not", "have", "remember", "anything"), $doc->getDocumentData());
 }
Пример #2
0
 public function tokenizeAction($url)
 {
     $text = $this->fetchText($url);
     //$tok = new WhitespaceAndPunctuationTokenizer();
     $tok = new PennTreeBankTokenizer();
     $tokens = $tok->tokenize($text);
     $stop = new StopWords($this->stopwords);
     $doc = new TokensDocument($tokens);
     $doc->applyTransformation(Normalizer::factory("English"));
     $doc->applyTransformation($stop);
     $tokens = $doc->getDocumentData();
     // More filtering
     foreach ($tokens as $k => $v) {
         $tokens[$k] = strtolower($tokens[$k]);
         $tokens[$k] = trim($tokens[$k], '.');
         //if (in_array($v, $this->stopwords)) unset($tokens[$k]);
         if (strlen($v) <= 3) {
             unset($tokens[$k]);
         }
     }
     // Count the rest
     $count = array_count_values($tokens);
     arsort($count);
     print "<pre>";
     print_r($count);
     print "</pre>";
     print "<hr>";
     print_r($tokens);
     return new Response();
 }
Пример #3
0
 /**
  * @dataProvider provideStemmers
  */
 public function testStemmer(Stemmer $stemmer)
 {
     $tokens = explode(" ", "this renowned monster who had come off victorious in a hundred fights with his pursuers was an old bull whale of prodigious size and strength from the effect of age or more probably from a freak of nature a singular consequence had resulted he was white as wool");
     $stemmed = $stemmer->stemAll($tokens);
     $doc = new TokensDocument($tokens);
     $this->assertNotEquals($stemmed, $doc->getDocumentData());
     $doc->applyTransformation($stemmer);
     $this->assertEquals($stemmed, $doc->getDocumentData());
 }
Пример #4
0
 /**
  * @dataProvider provideTokens
  */
 public function testTokensDocument($tokens)
 {
     $doc = new TokensDocument($tokens);
     $transformer = new IdentityTransformer();
     $this->assertEquals($tokens, $doc->getDocumentData());
     $doc->applyTransformation($transformer);
     $this->assertEquals($tokens, $doc->getDocumentData());
     $tdoc = new TrainingDocument("", new TokensDocument($tokens));
     $tdoc->applyTransformation($transformer);
     $this->assertEquals($tokens, $tdoc->getDocumentData());
 }
	<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Individual Steps</h4>
      </div>
      <div class="modal-body" id="putmodal">
        

     
<?php 
while ($row = mysql_fetch_array($query_run)) {
    $responseStop = $row['resp'];
    $d = new TokensDocument(explode(" ", $responseStop));
    if ($type == "stop") {
        $stop = new StopWords(array("you're", "-", "using", 'itemprop="text">', " ", 'class="post-text"', "=", "a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also", "although", "always", "am", "among", "amongst", "amoungst", "amount", "an", "and", "another", "any", "anyhow", "anyone", "anything", "anyway", "anywhere", "are", "around", "as", "at", "back", "be", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom", "but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven", "else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own", "part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the"));
        echo "<center>Stop words:</center><br/>";
        $d->applyTransformation($stop);
        print_r($d->getDocumentData());
        echo "<br/>========================================>>>>>>>><br/>";
    } else {
        echo "<center>Stemmer:</center><br/>";
        //echo $d->getDocumentData();
        $stemmer = new PorterStemmer();
        $d->applyTransformation($stemmer);
        print_r($d->getDocumentData());
        //stemmer applied
        echo "<br/>========================================>>>>>>>><br/>";
    }
Пример #6
0
<?php

/**
 * Example of using stopwords when using NlpTools
 *
 * @author Glenn De Backer <*****@*****.**>
 */
include 'vendor/autoload.php';
use NlpTools\Tokenizers\WhitespaceTokenizer;
use NlpTools\Documents\TokensDocument;
use NlpTools\Utils\StopWords;
// text we will be converting into tokens
$text = "PHP is a server side scripting language";
// define a list of stop words
$stop = new StopWords(array("is", "a", "as"));
// initialize Whitespace tokenizer
$tokenizer = new WhitespaceTokenizer();
// init token document
$doc = new TokensDocument($tokenizer->tokenize($text));
// apply our stopwords
$doc->applyTransformation($stop);
// print filtered tokens
print_r($doc->getDocumentData());