Hack 49 Interrogate Trust Networks with TrustBot


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 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 http://trust.mindswap.org.
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 trust.mindswap.org. 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:
http://trust.mindswap.org/cgi-bin/botquery.cgi?from=source@example.comsink@example.com
The email address source@example.com
should be replaced with the email address of the source, and
sink@example.com 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 ("http://trust.mindswap.org/cgi-bin/botquery." +
"cgi?from=" + sourceEmail + " + 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 golbeck@cs.umd.edu to bob@example.com
The following code should be added into the
onMessage method in the PircBot subclass (after
line 54 of the MyBot.java 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