获取 PHP 中句子中的第一个“内容词”


get the first `content word` in a sentence in php

假设我有一句话:

$str="Some remarks on singular solutions of a nonlinear equation";

如何获得$str的第一个内容词? 在这里,如果一个词是名词,我称它为内容词,因此它们是:

remarkssingularsolutionsequation

其余的被视为功能词。

更新假设我们有函数词列表

$fword=array("some","on","of", "a");

使用 PHP 爆炸函数,按间隔拆分字符串。

爆炸 — 按字符串拆分字符串

返回一个字符串数组,每个字符串都是字符串的子字符串,该字符串通过在字符串分隔符形成的边界上拆分它而形成。

$str = "Some remarks on singular solutions of a nonlinear equation";
$arr = explode(' ', trim($str));
// And then for each word in $arr check if it passes your criteria

如果您想知道该单词是否是名词,请检查WordNet Project http://sourceforge.net/projects/wnsqlbuilder/files/wnsqldatabase/或具有英语单词类型的类似数据库中$arr的每个单词。