Erlang,提取标签

时间:2014-11-18 11:22:56

标签: binary erlang extract hashtag

我试图从使用时检索到的列表中提取一个#标签 twi api。

我用它来提取主题标签:

case extract(<<"entities">>, L) of 
   {found, {TE}} ->
       {found, Hashtags} = extract(<<"hashtags">>, TE);
   not_found -> Hashtags = hash_not_found
   end,

extract(K, L) ->
 case lists:keyfind(K, 1, L) of
   {_, M} -> {found, M};
   false  -> not_found
 end.

这给我一个格式为:

的主题标签
[{[{<<"text">>,<<"London">>},{<<"indices">>,[120,127]}]}]

我希望仅从中提取标签,在这种情况下将是伦敦。 每次我提取推文时,此标记都会有所不同。 任何想法或建议都表示赞赏。

除非我真的需要,否则我不希望更改早期的代码。我更愿意学习如何从该列表中提取我需要的内容。

1 个答案:

答案 0 :(得分:0)

猜测extract函数的作用,这样的事情应该有效:

case extract(<<"hashtags">>, TE) of
  {found, Hashtags} ->
    case extract(<<"text">>, Hashtags) of 
      {found, HashtagTexts} -> HashtagTexts;
      not_found -> hash_not_found
    end;
  not_found -> hash_not_found
end

另请参阅标准库中的proplists模块。