Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从字符串中匹配对和三元组子字符串_Python_String_Algorithm - Fatal编程技术网

Python 从字符串中匹配对和三元组子字符串

Python 从字符串中匹配对和三元组子字符串,python,string,algorithm,Python,String,Algorithm,我有一个系统,可以从用户那里接收字符串。我有一个单词列表,它基本上分类了这个单词所属的类别。这将看起来像这样: classifier = {"delhi":"place", "new-delhi":"place", "java":"skill", "python":"skill"} 假设查询结果是新德里的java作业。我对实施的想法如下: 弹弦 从(0,1,2)、(1,2,3)等字符串中选择三元组 如果三元组映射到分类器dict,则从字符串中弹出它,存储它并继续处理 同样地,这项任务也会对

我有一个系统,可以从用户那里接收字符串。我有一个单词列表,它基本上分类了这个单词所属的类别。这将看起来像这样:

classifier = {"delhi":"place",
"new-delhi":"place",
"java":"skill",
"python":"skill"}
假设查询结果是新德里的
java作业
。我对实施的想法如下:

  • 弹弦
  • 从(0,1,2)、(1,2,3)等字符串中选择三元组
  • 如果三元组映射到
    分类器
    dict,则从字符串中弹出它,存储它并继续处理
同样地,这项任务也会对双人和单人重复

上面的方法将给我大约3n的复杂性,其中n是字符串的长度


有没有其他/更好的方法可以做到这一点?

作为建议,可以将搜索过程委托给redis、cassandra或aerospike等专用工具……我已经为搜索设置了Solr服务器。我只想能够对数据进行分类,以便在移动中应用过滤器。首先构建一个索引的
分类器如何?类似于
{“places_index”:{a':[“a1”,“a2”。]}
然后在分类器['skills_index']['j']中搜索一个查询部分
如果'java'在分类器['skills_index']['j']
中,假设我有200个以字母'j'开头的技能和200个以'j'开头的位置,我将不得不迭代400次来检查java是一个技能还是一个位置。最好是保留一本字典,因为这样可以为我提供恒定的查找时间。作为建议,也许可以将搜索过程委托给一个专用工具,如redis、cassandra或aerospike……我已经为搜索设置了Solr服务器。我只想能够对数据进行分类,以便在移动中应用过滤器。首先构建一个索引的
分类器如何?类似于
{“places_index”:{a':[“a1”,“a2”。]}
然后在分类器['skills_index']['j']中搜索一个查询部分
如果'java'在分类器['skills_index']['j']
中,假设我有200个以字母'j'开头的技能和200个以'j'开头的位置,我将不得不迭代400次来检查java是一个技能还是一个位置。最好是留一本字典,因为那会给我提供固定的查找时间。