Commit 6a0eec3b03c69a57e761c235c38dd9c56dd491bd
1 parent
410cbe3b35
Exists in
master
Fixed readme and documentation
Showing 2 changed files with 74 additions and 2 deletions Side-by-side Diff
README.md
... | ... | @@ -5,10 +5,56 @@ The Twitter Microblog Track runs a rather special Evaluation as a service |
5 | 5 | model, which allows participants to connect to a server to perform queries |
6 | 6 | using a thrift-based API. This package provides a set of Go bindings for |
7 | 7 | performing queries to the service, in addition to a wrapper library which |
8 | -simplifes it's use. | |
8 | +simplifies its use. | |
9 | 9 | |
10 | 10 | ## Requirements |
11 | 11 | The library requires the thrift package from Apache, which can be installed |
12 | 12 | using: |
13 | 13 | |
14 | - go get git.apache.org/thrift.git/lib/go/thrift | |
15 | 14 | \ No newline at end of file |
15 | + go get git.apache.org/thrift.git/lib/go/thrift | |
16 | + | |
17 | +## Installing | |
18 | +Go get can handle installation for you. | |
19 | + | |
20 | + go get git.apache.org/thrift.git/lib/go/thrift | |
21 | + | |
22 | +## Usage | |
23 | +The library is modelled loosely on the official Microblog track client, which is written in Java. It’s very simple and implements 3 basic actions: 1) Create a connection 2) Perform a query and return results and 3) Close the connection. All of these are demonstrated in the example below. | |
24 | + | |
25 | + package main | |
26 | + | |
27 | + import ( | |
28 | + "fmt" | |
29 | + "log" | |
30 | + "mirgit.dcs.gla.ac.uk/JamesMcMinn/twitter-tools-go" | |
31 | + ) | |
32 | + | |
33 | + func main() { | |
34 | + // Create a new client using the settings in conf.json | |
35 | + client, err := twittertools.NewClientFromConf("conf.json") | |
36 | + if err != nil { | |
37 | + log.Fatal(err) | |
38 | + } | |
39 | + defer client.Close() | |
40 | + | |
41 | + // query the server for "glasgow", retreive the top 50 results | |
42 | + // -1 signifies that there is no maximum tweet ID | |
43 | + results, err := client.Search("Glasgow", 50, -1) | |
44 | + if err != nil { | |
45 | + log.Fatal(err) | |
46 | + } | |
47 | + | |
48 | + // Iterate over the results, printing text from each tweet | |
49 | + for k, result := range results { | |
50 | + fmt.Println(k, result.Text) | |
51 | + } | |
52 | + } | |
53 | + | |
54 | +The example uses a conf.json file (example below) to load the server details and your team details. If you’d rather hard-code the values, the `twittertools.NewClientFromDetails(host, port, group, token)` function allows you to create a new client and specify the details manually. | |
55 | + | |
56 | + { | |
57 | + "Host": "server.address.edu", | |
58 | + "Port": 9091, | |
59 | + "Group": "UrTeamName", | |
60 | + "Token": "de4db33f" | |
61 | + } | |
16 | 62 | \ No newline at end of file |
client.go
1 | +// This library is designed to replicate some of the basic functionality | |
2 | +// found in the Java version of the Twitter Tools for the TREC Mircoblog | |
3 | +// track. | |
4 | +// | |
5 | +// Example Usage | |
6 | +// | |
7 | +// // Create a new client using the settings in conf.json | |
8 | +// client, err := twittertools.NewClientFromConf("conf.json") | |
9 | +// if err != nil { | |
10 | +// log.Fatal(err) | |
11 | +// } | |
12 | +// defer client.Close() | |
13 | +// | |
14 | +// // query the server for "glasgow" and retreive the top 50 results | |
15 | +// // -1 signifies that there is no maximum tweet ID | |
16 | +// results, err := client.Search("Glasgow", 50, -1) | |
17 | +// if err != nil { | |
18 | +// fmt.Println(err) | |
19 | +// } | |
20 | +// | |
21 | +// // Itterate over the results, printing the text from each tweet | |
22 | +// for k, result := range results { | |
23 | +// fmt.Println(k, result.Text) | |
24 | +// } | |
25 | +// | |
26 | + | |
1 | 27 | package twittertools |
2 | 28 | |
3 | 29 | import ( |