views:

230

answers:

2

So I've looked at this use of the freebase API and I was really impressed with the translations of the name that it found. IE Rome, Roma, Rom, Rzym, Rooma,로마, 罗马市. This is because I have a database of some 5000+ location names and I would very much like all French, German or Korean translations for these English names.

The problem is I spent about two hours clicking around freebase, and could find no way to get a view of city/location names in a different language mapped to English. So I'd love it if someone who understands what freebase is and how it's organized could get me a link to that view which theoretically I could then export.

Also I just wanted to share this question because I'm totally impressed with freebase and think if people haven't looked at it they should.

+4  A: 

The link you posted uses mjt, a javascript framework designed for Freebase.

The Query they use.

 mjt.freebase.MqlRead([{
     limit: 100,
     id:qid,
     /* allow fuzzy matches in the value for more results... */
     /* 'q:name': {'value~=': qname, value:null, lang: '/lang/'+qlang}, */
     'q:name': {value: qname, lang: '/lang/'+qlang},

     type: '/common/topic',
     name: [{
         value:null,
         lang:{
             id:null,
             name:{
                 value:null,
                 lang:'/lang/en',
                 optional:true
             },
             'q:name':{
                 value:null,
                 lang:'/lang/'+qlang,
                 optional:true
             }
         }
     }],
     article: [{id:null, limit:1}],
     image: [{id:null, limit:1, optional:true}],
     creator: null,
     timestamp:null
   }])

Where: qlang - is your desired language to translate too. qname - is is the location to query.

To get the link you want, you'll need the API, and you can convert the above query to a link that will return a JSON object containing the translated string.

Brian Gianforcaro
+4  A: 

The query

[{
     limit: 100,
     type: '/location/location',
     name: [{
         value: null,
         lang: {
             name: {
                 value: null,
                 lang: '/lang/en',
             },
         }
     }],
}];

returns for every location and every language, the name of that location in that language. The results are organized by language. For example, here is a very small segment of the return value:

                    {
                      'lang': {
                                  'name': {
                                              'lang': '/lang/en',
                                              'value': 'Russian'
                                            }
                                },
                      'value': 'Сан-Франциско'
                    },
                    {
                      'lang': {
                                  'name': {
                                              'lang': '/lang/en',
                                              'value': 'Swedish'
                                            }
                                },
                      'value': 'San Francisco'
                    },
                    {
                      'lang': {
                                  'name': {
                                              'lang': '/lang/en',
                                              'value': 'Portuguese'
                                            }
                                },
                      'value': 'São Francisco (Califórnia)'
                    },

For a no-programming solution, copy-paste the following into an HTML file and open it with your browser:

<html><head>
<script type="text/javascript" src="http://mjtemplate.org/dist/mjt-0.6/mjt.js"&gt;&lt;/script&gt;
</head>
<body onload="mjt.run()">
<div mjt.task="q">
  mjt.freebase.MqlRead([{
    limit: 10,
    type: '/location/location',
    name: [{
      value:null,
        lang:{
          name:{
            value:null,
            lang:'/lang/en',
          },
        }
    }],
  }])     
</div>

<table><tr mjt.for="topic in q.result"><td>
<table><tr mjt.for="(var rowi = 0; rowi &lt; topic.name.length; rowi++)"
  mjt.if="rowi &lt; topic.name.length" style="padding-left:2em"><td>
  <pre mjt.script="">
    var name = topic.name[rowi];
  </pre>
  ${(name.lang['q:name']||name.lang.name).value}:
</td><td>$name.value</td></tr></table></td></tr></table></body></html>

Of course, that will only include the first 10 results. Up the limit above if you want more. (By the way, not only is Freebase cool, so is this mjt templating language!)

A. Rex