Hightman 论坛

完整版: scws_has_word的逻辑问题
您当前正在浏览的是一个简化版本. 要观看完整版本, 请点这儿.
分页: 1 2
引用:int scws_has_word(scws_t s, char *xattr)
{
int off, cnt, xmode = SCWS_NA;
scws_res_t res, cur;
char *word;
word_attr *at = NULL;

if (!s || !s->txt)
return 0;

__PARSE_XATTR__;

// save the offset. (cnt -> return_value)
off = s->off;
cnt = s->off = 0;
while (!cnt && (cur = res = scws_get_result(s)) != NULL)
{
do
{
/* check attribute filter */
if (at != NULL)
{
if ((xmode == SCWS_NA) && _attr_belong(cur->attr, at))
cnt = 1;

if ((xmode == SCWS_YEA) && !_attr_belong(cur->attr, at))
cnt = 1;
}
}
while (!cnt && (cur = cur->next) != NULL);
scws_free_result(res);
}
s->off = off;
return cnt;
}

如果xattr是NULL,返回的将会是0
另外,scws_get_words返回的包括标点,不知道是否是设计的原意?
关于has_word, 不是很明白你的意思, has_word 用于检测当前文本中是否包含这些属性的词。
scws_get_words 是按词性返回分词结果,标点的词应该默认应该是 un 或 # 之类可以自行排除。
(2010-07-29 02:48 PM)hightman 提到: [ -> ]关于has_word, 不是很明白你的意思, has_word 用于检测当前文本中是否包含这些属性的词。
scws_get_words 是按词性返回分词结果,标点的词应该默认应该是 un 或 # 之类可以自行排除。

关于has_word,我的意思是说,当我不传属性参数,返回的会是0
(2010-07-29 01:10 PM)backluck 提到: [ -> ]
引用:int scws_has_word(scws_t s, char *xattr)
{
int off, cnt, xmode = SCWS_NA;
scws_res_t res, cur;
char *word;
word_attr *at = NULL;

if (!s || !s->txt)
return 0;

__PARSE_XATTR__;

// save the offset. (cnt -> return_value)
off = s->off;
cnt = s->off = 0;
while (!cnt && (cur = res = scws_get_result(s)) != NULL)
{
do
{
/* check attribute filter */
if (at != NULL)
{
if ((xmode == SCWS_NA) && _attr_belong(cur->attr, at))
cnt = 1;

if ((xmode == SCWS_YEA) && !_attr_belong(cur->attr, at))
cnt = 1;
}
}
while (!cnt && (cur = cur->next) != NULL);
scws_free_result(res);
}
s->off = off;
return cnt;
}

如果xattr是NULL,返回的将会是0
另外,scws_get_words返回的包括标点,不知道是否是设计的原意?


主要是while循坏里面,如果变量at为NULL, “cnt=1”就永远不会执行。
这有什么关系呢,AT为NULL时返回0也合乎情理啊。
分页: 1 2
Reference URL's