}
public UserAccount persist(final User tweetUser) {
UserAccount userAccount = accountForUser(tweetUser);
Agent agent = agentForUser(tweetUser, userAccount);
Set<Thing> equivalentAgents = new HashSet<Thing>();
String semanticTweetUri
= "http://semantictweet.com/" + tweetUser.getScreenName() + "#me";
equivalentAgents.add(
designate(semanticTweetUri, Thing.class));
agent.setOwlSameAs(equivalentAgents);
if (null != tweetUser.getName()) {
agent.setName(tweetUser.getName());
}
if (null != tweetUser.getDescription()) {
agent.setRdfsComment(tweetUser.getDescription());
}
if (null != tweetUser.getLocation()) {
SpatialThing basedNear = agent.getBasedNear();
if (null == basedNear) {
basedNear = spatialThing();
agent.setBasedNear(basedNear);
}
basedNear.setRdfsComment(tweetUser.getLocation());
}
if (null != tweetUser.getUrl()
&& TweetSyntax.URL_PATTERN.matcher(tweetUser.getUrl()).matches()) {
// Note: we can't easily delete an existing homepage (removing its
// rdf:type statement), as it might be the homepage of another
// agent. Therefore, "orphaned" Document resources are possible.
Document homepage = designate(tweetUser.getUrl(), Document.class);
agent.setHomepage(homepage);
}
if (null != tweetUser.getProfileImageUrl()
&& TweetSyntax.URL_PATTERN.matcher(tweetUser.getProfileImageUrl()).matches()) {
// Note: we can't easily delete an existing image (removing its
// rdf:type statement), as it might be the image of another
// agent. Therefore, "orphaned" Image resources are possible.
Image depiction = designate(tweetUser.getProfileImageUrl(), Image.class);
agent.setDepiction(depiction);
}
if (null != tweetUser.getFollowers()) {
Set<Agent> agents = new HashSet<Agent>();
for (User u : tweetUser.getFollowers()) {
UserAccount ua = accountForUser(u);
Agent ag = agentForUser(u, ua);
agents.add(ag);
}
agent.setKnownBy(agents);
}
if (null != tweetUser.getFollowees()) {
Set<Agent> agents = new HashSet<Agent>();
for (User u : tweetUser.getFollowees()) {
UserAccount ua = accountForUser(u);
Agent ag = agentForUser(u, ua);
agents.add(ag);
}
agent.setKnows(agents);
}