首页 文章

Erlang,提取标签

提问于
浏览
0

我试图从使用twiter 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

    猜测 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模块 .

相关问题