Previous Section  < Day Day Up >  Next Section

Hack 49 Interrogate Trust Networks with TrustBot

figs/expert.gif figs/hack49.gif

Use the network of trust ratings available on the Web to recommend how much to trust an unknown individual and send your recommendations over IRC.

Trust networks are appearing all over the Web, from web sites like Advogato and Epinions to the social networks of the Semantic Web. You were just shown how to create a bot that would load data from a FOAF network [Hack #48] and provide that information via IRC. This hack will introduce some simple extensions to FOAF that will parse information about trust relationships and use it to make recommendations about how much a person should trust a stranger.

The Advogato project ( is a community site for free software developers. It uses group trust metrics for peer certification to limit access to certain sections of the site.

Epinions ( uses consumer reviews to rate products and sellers. Users build a web of trusted people, and that data is used to make recommendations across the network.

The Trust Project ( is a web site dedicated to building a distributed, open trust network. The data and results in this hack use this network.

The premise for trust networks appears frequently in everyday life. If a person meets a new colleague at work, it is common to ask around about this person. The assumption is that people you trust will give you good information about whether or not to trust the new person. Unlike FOAF, which connects people only by whether or not they know one another, trust networks add ratings to those relationships. Because trust ratings can be represented numerically, it is simple to compose relationships over paths.

What kind of trust ratings to give and how to make recommendations based on that is an active area of social networks research. In this example, people rate each other's trustworthiness on a scale from 1 to 10, where 1 is very low trust and 10 is very high trust. This network is stored on the Semantic Web as an extension of FOAF. To learn more about the network or add yourself, visit The Trust Project at Recommendations about how much to trust a person will be made using a recursive system. The Trust Project will make these calculations, and you can use the calculation they provide instead of writing your own code.

7.7.1 Getting Trust Data

In FOAFBot, there is code to parse RDF and OWL files and build objects in the Person class. The TrustBot can be built in the same way. You could modify the FOAFBot code so it would process trust files, store the proper information in the Person class (with modifications), and then write a series of functions to make trust inferences. Instead of writing all of that, you can use the server at It has a database of information from spidered and parsed trust files. You can connect to that server and make queries about how much two people should trust each other.

As with FOAF, people are identified by email address in the trust network. Passing the email address of the person for whom the inference is being made (the source) and the person about whom it is being made (the sink) will return the recommendation about how much the source should trust the sink.

The result will be retrieved from a URL in this form:

The email address should be replaced with the email address of the source, and should be replaced with the email address of the sink. The result will return a full sentence that the bot can print out. When this URL is accessed, it prints out a single line of text that has the recommended trust level from the source to the sink. The following getTrust() method creates the correct URL and then loads its result:

private String getTrust(String sourceEmail, String sinkEmail) {


    URLConnection conn = null;

    DataInputStream data = null;

    String line;

    StringBuffer buf = new StringBuffer( );

    try {

        URL u = new URL ("" +

               "cgi?from=" + sourceEmail + "&to=" + sinkEmail);

        conn = u.openConnection( );

        conn.connect( );

        data = new DataInputStream(new BufferedInputStream(

                conn.getInputStream( )));


        while ((line = data.readLine( )) != null) {

            buf.append(line + "\n");


        data.close( );

        return buf.toString( );


    catch (Exception e) {

        return "Error. Unable to process this request";



With this method, the only remaining step is to parse a request from the user, extract the email addresses, and show the result of the method in the IRC interface.

7.7.2 Modifying the IRC Interface

Using the same code from FOAFBot, the only change you need to make is to add a handler for a command that will process a trust value. The format of that command will mimic the FOAF-based commands. This will allow users to type message like this:

<golbeck> Trustbot, trust  to

The following code should be added into the onMessage method in the PircBot subclass (after line 54 of the file in the FOAFBot code):

if (query.equals("trust")) {

    String response = "";

    // Get the first email address.

    String email = t.nextToken( );

    // Eliminate the "to".

    t.nextToken( );

    // Get the second email address.

    String inQuestionEmail = t.nextToken( );


    response = getTrust(email, inQuestionEmail);

    sendMessage(channel, response);    


With this addition, the bot is now ready to handle trust questions and show the user the result that it retrieves from the Web.

7.7.3 The Results

In Figure 7-6, see the TrustBot being queried for trust recommendations.

Figure 7-6. Using TrustBot to give guidance on trust

Now you can use the bot to find out how much you should trust other people, even if you don't know them already.

Jennifer Golbeck

    Previous Section  < Day Day Up >  Next Section