Gold Parser文本词法分析

在westdc的搜索输入字符串时用了一下Gold Parser,感觉真是个好东西,不过学起来有点费劲,花了我3天时间,才逐渐明白并动手做了一个比较简单的字串分析器。代码如下:

! GOLD Parser Builder
! Version 3.4.4
!
"Name" = "Simple search Grammer"
"Version" = "1.0"
"Author" = "Zhuotong Nan"

"Start Symbol" = <Query>

!—————–Sets
!Valid char for string keyword
{kw1} = {All Valid} – {Control Codes} – ["]

!Valid char for non-string keyword
{kw2} = {kw1} – {Whitespace} -[()]

!—————–Terminal

SimpleKw = {kw2}+
StringKw = ‘"’ {kw1}* ‘"’

!—————–Rules

<Keyword> ::= SimpleKw | StringKw

<Unit> ::= <Keyword>
| ‘(‘ <Query> ‘)’

<And> ::= <Query> <Unit>
| <Query> ‘and’ <Unit>

<Or> ::= <Query> ‘or’ <Unit>

<Query> ::= <And>
| <Or>
| <Unit>

支持 and, or查询,kw1 and kw2 可以省略为 kw1 kw2,支持括号优先级,支持""指定字串
通过CalithaLib engine连接到c#应用程序
语法并不复杂,但用于arcims的search_metadata比较别扭,如果将分析出来的keywords组织成arcims识别的search_metadata结构费了比较大的劲

中文搜索仍有问题,明天再检查,arcims是否有专门的设置没有。

Leave a Reply

Your email address will not be published. Required fields are marked *