Blog

2008 04 posts (4)

Ordering: Ascending Descending

1. Semantic social networks

2008-04-02 14:05:45 by Martynas Jusevičius

Lately there has been a growing dissatisfaction in the user communities of social networks and other user-based websites which were built with an intention to lock and control the data that users provide. Users complain about not having control over profile data and social relationships they have established and not being able to export them in machine readable formats, which makes reuse and integration of this data virtually impossible. This resulted in several initiatives:

Open Social Web
Demands ownership, control, and freedom of personal information on the social web
Social Network Portability
Demands ability to import profile information and social network (based on Microformats)
DataPortability
Encourages standards-based data portability in general
OpenID
Promotes single digital identity
OpenSocial
Defines a common API for social applications across multiple websites

The main problem seems to be data portability in general, and we have already argued that it is a sweet spot for semantic technologies. However, there are several Semantic Web projects directly addressing issues of social networks:

Friend of a Friend (FOAF)
Aimed at creating a Web of machine-readable pages describing people, the links between them and the things they create and do
Semantically Interlinked Online Communities (SIOC)
Provides methods for interconnecting discussion methods such as blogs, forums and mailing lists to each other

In combination with Linked Data, FOAF would allow import of friend profiles from one website to another, and SIOC would enable structured queries over distributed user-generated content. Social networks could reuse semantic data from sites like DBpedia and be valuable sources of such data themselves. These were the main ideas in Tim Berners-Lee Giant Global Graph vision and Brad Fitzpatrick's thoughts on Social Graph.
Leigh Dodds wrote about this back in 2004, but things have advanced slowly. There exist SIOC plugins for several blog engines, and LiveJournal is publishing FOAF data, but portability still has to gain momentum, most likely by support from major sites.

Add a comment Comments (1169)

2. Recursion in XSLT

2008-04-09 23:52:48 by Martynas Jusevičius

XSLT, which is great for web templating, is a functional language and has no loops or mutable variables. These constructs have to be replaced with recursion and parameters. For example, if you would like to loop until a certain number and print the counter, you would have to use recursion.
Recursion in XSLT is implemented using <xsl:apply-templates> or <xsl:call-template> together with <xsl:with-param> and <xsl:param>.

The general logic is to call or apply a template with some initial parameter value, get the necessary work done inside of the template, and let it call itself with a modified parameter. Considering the loop example, it would mean calling the template with 0 as initial counter parameter, printing it out in the template, and calling the template recursively with counter increased by one with the condition that it still is smaller than the target number.
As a complete example we provide a template for converting line breaks in a string into HTML <br/> elements:

<xsl:template name="process-line-breaks">
	<xsl:param name="text"/>
	<xsl:variable name="break" select="'&#10;'"/> <!-- entity for line break character, might differ according to platform -->
	<xsl:choose>
		<xsl:when test="contains($text, $break)">
			<xsl:value-of select="substring-before($text, $break)"/>
			<br/>
			<xsl:call-template name="process-line-breaks">
				<xsl:with-param name="text" select="substring-after($text, $break)"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$text"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

The template takes a text string as a parameter and tries to locate a line break in it. If that suceeds, the string part before the break is the output, followed by a <br/>, and the template is applied recursively on the string part after the break. If there are no more breaks in the string parameter, the remaining string becomes the output and the template terminates. In each step the template is left with a smaller and smaller remainder of the original string, while the preceding part becomes template output with line breaks replaced.
The template can be applied on a text content like this:

<xsl:template match="text()" mode="process-line-breaks">
	<xsl:call-template name="process-line-breaks">
		<xsl:with-param name="text" select="."/>
	</xsl:call-template>
</xsl:template>

Add a comment Comments (11)

3. kbh.dk

2008-04-18 12:04:15 by Martynas Jusevičius

I started working as a freelancer on kbh.dk. From the English description:

Kbh.dk is a social network for everybody that live in or care about Copenhagen.

We will launch a Public Beta version in May 2008. In the first phase the web site will be mainly in Danish but we’re working hard to get full internationalization as soon as possible.

The project is driven by the wish to create a socially connected metropolis. Kbh.dk will be the place where the people of Copenhagen inspire each other to use the city - together. The project is financed by the Municipality of Copenhagen.

Kbh.dk helps you to

  • Find people that share your interests and connect through groups
  • Promote your interests with video, photos and blogs
  • Network with your friends - and use the city with them
  • Invite others to the events you are organizing or following

I am responsible for the events part. Users will be able to create them, but there will also be events imported from a third-party aggregation webservice.

It seems like it is going to be fun, I'm excited :)

Add a comment Comments (7)

4. Calculating distance in SQL

2008-04-22 21:27:53 by Martynas Jusevičius

There was a need recently to calculate distances between locations that have a latitude and longitude defined and retrieve the ones that are closest. I came up with a little SQL query, which is based on the Pythagorean theorem and simple math. It does not take into account that Earth is a sphere (in that case you would need to use something more complicated like the Haversine formula), but should be accurate enough for relatively short distances in range of tens of kilometers.

SELECT *, SQRT(POW(L2.lat - L1.lat, 2) + POW(L2.lng - L1.lng, 2)) AS Distance
FROM Location AS L1
INNER JOIN Location AS L2
WHERE L1.id = 1 AND L1.id != L2.id
ORDER BY Distance
LIMIT 10

The query makes a self join on the Location table, which is assumed to contain lat and lng columns. It retrieves 10 locations closest to location which ID is 1. If you remove that condition and the LIMIT clause, you will get a table of distances between all locations.
You can also put some limit on distance as radius (in degrees), but it does not really translate into (kilo)meters using this formula.

Add a comment Comments (2853)

Ordering: Ascending Descending