使用F#Freebase类型提供程序访问链接项的正确方法是什么

时间:2013-02-08 08:19:46

标签: f# freebase type-providers f#-data

我有以下代码,目的是列出Freebase上列出的证券交易所网站:

#if INTERACTIVE
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.1.7.4\lib\40\FSharpx.TypeProviders.dll"
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.Freebase.1.7.4\lib\40\FSharpx.TypeProviders.Freebase.dll"
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.Freebase.1.7.4\lib\40\FSharpx.TypeProviders.Freebase.DesignTime.dll"
#endif 

let GetExchanges() =
    let dc = FreebaseData.GetDataContext()
    dc.DataContext.SendingRequest.Add(fun e -> printfn "url: %s" e.RequestUri.AbsoluteUri)

    dc.``Products and Services``.Business.``Stock exchanges``
    |> Seq.truncate 10
    |> Seq.iter (fun exchange -> printfn "Exchange: %s" exchange.Name
                                 exchange.``Official website``
                                 |> Seq.iter (fun site -> printfn "%s" site.Name))

没有最后两行(即只列出Exchange名称),代码工作正常。使用这些行我得到400(错误请求)。

该行生成的URL为:

https://www.googleapis.com/freebase/v1/mqlread?query=%5B%7B%22/type/object/id%22:null,%20%22/type/object/name%22:null%20,%20%22optional%22:true,%20%22/type/object/type%22:%22/type/uri%22,%20%22!/common/topic/official_website%22:%20%5B%7B%22/type/object/id%22:%22/en/amex%22,%22/type/object/type%22:%22/common/topic%22%20,%20%22limit%22:%20500%7D%5D%7D%5D&cursor

...如果我浏览到我从Freebase获得这个:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "Can't reverse /common/topic/official_website as it expects /type/uri, not an object"
   }
  ],
  "code": 400,
  "message": "Can't reverse /common/topic/official_website as it expects /type/uri, not an object"
 }
}

我使用正确的方法访问链接的实体吗?如果是这样,这是类型提供程序中的错误吗?我在访问其他链接实体时遇到类似的错误。

2 个答案:

答案 0 :(得分:4)

此类型提供程序中的错误已修复:https://github.com/fsharp/FSharp.Data/issues/68

答案 1 :(得分:4)

就像错误所说的那样,你不能反转属于原始值属性的属性。您需要将查询内部翻出来,使其看起来像:

[{
  "/type/object/id": "/en/amex",
  "/common/topic/official_website": [{
    "value":    null,
    "optional": true
  }]
}]​

库必须具有一些原始值的知识,所以也许这对于包含/ type / text,/ type / rawstring等的任何列表添加/ type / uri都很简单。