【问题标题】:Erlang, extract hashtagErlang,提取主题标签
【发布时间】:2015-01-15 13:40:28
【问题描述】:

我正在尝试从使用时检索的列表中提取主题标签 推特 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]}]}]

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

我不希望更改之前的代码,除非我真的必须这样做。我更愿意学习如何从该列表中提取我需要的内容。

【问题讨论】:

    标签: binary erlang extract hashtag


    【解决方案1】:

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

    【讨论】:

    • 除非我可以在该代码中为 {found,[]}} 添加某种子句,否则这是行不通的。
    • 如前所述,这取决于extract 的实现方式。 not_found{found, []} 有什么区别?
    • 我的代码已被编辑。如果有帮助,我添加了提取功能。
    猜你喜欢
    • 2016-06-20
    • 2017-04-12
    • 2021-07-30
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    相关资源
    最近更新 更多