即插即用简单标记库
simpletag的Python项目详细描述
用法
>>> import simpletag >>> ns = simpletag.TextNS('myTextTagSpace') # Create a namespace of text IDs ... # Create integer IDs namespace with `simpletag.IntNS()` >>> doc_1 = '/a/b' >>> tags_1 = ['tag'] >>> doc_2 = '/b/a' >>> tags_2 = 'tag simple!' >>> ns.update(doc_1, tags_1) >>> ns.update(doc_2, tags_2) >>> print [ doc for doc in ns.query_ids('tag') ] [u'/a/b', u'/b/a'] >>> print [ tag for tag in ns.query_tags(doc_1) ] [u'tag'] >>> print [ st for st in ns.stats() ] [{ 'term': u'simple', 'documents': 1, 'occurrences': 1 }, { 'term': u'tag', 'documents': 2, 'occurrences': 2 }] >>> ns.purge()
标记查询
使用sqlite fts查询语法的标记集查询。
>>> ns.update(1, [u'民主', u'自由']) >>> ns.update(2, [u'民主', u'Cxin123']) >>> query = '' ... # Query IDs of tags '民主' but not 'Cxin*' (tags start with Cxin) >>> if ns.using_parenthesis_query: >>> query = u'民主 NOT Cxin*' >>> else: >>> query = u'民主 -Cxin*' >>> print [tag for tag in ns.query_ids(query)] [1]
注意sqlite支持standard和parenthesis语法,以及
在编译sqlite时,这两个选项是互斥启用的。检测哪一个
正在通过simpletag.ns.using_parenthesis使用。参见SQLite
documentation了解
更多信息。
待办事项
- 作为烧瓶插件
- 基准
- 进一步的标签分析(例如top-k~knn分类)