You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by sf...@apache.org on 2010/12/12 17:10:52 UTC

svn commit: r1044841 [6/11] - in /incubator/stanbol/trunk/fise: SemiAutomaticContentEnhancer/src/main/java/eu/iksproject/fise/sace/ SemiAutomaticContentEnhancer/src/main/java/eu/iksproject/fise/sace/ui/ SemiAutomaticContentEnhancer/src/main/java/eu/iks...

Modified: incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/WikipediaArticle.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/WikipediaArticle.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/WikipediaArticle.java (original)
+++ incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/WikipediaArticle.java Sun Dec 12 16:10:48 2010
@@ -18,179 +18,179 @@ package org.geonames;
 
 /**
  * a wikipedia article
- * 
+ *
  * @author marc@geonames
- * 
+ *
  */
 public class WikipediaArticle {
 
-	private String language;
+    private String language;
 
-	private String title;
+    private String title;
 
-	private String summary;
+    private String summary;
 
-	private String wikipediaUrl;
+    private String wikipediaUrl;
 
-	private String feature;
-
-	private int population;
-
-	private int elevation;
-
-	private double latitude;
-
-	private double longitude;
-	
-	private String thumbnailImg;
-
-	/**
-	 * @return Returns the elevation.
-	 */
-	public int getElevation() {
-		return elevation;
-	}
-
-	/**
-	 * @param elevation
-	 *            The elevation to set.
-	 */
-	public void setElevation(int elevation) {
-		this.elevation = elevation;
-	}
-
-	/**
-	 * @return Returns the feature.
-	 */
-	public String getFeature() {
-		return feature;
-	}
-
-	/**
-	 * @param feature
-	 *            The feature to set.
-	 */
-	public void setFeature(String feature) {
-		this.feature = feature;
-	}
-
-	/**
-	 * @return Returns the language.
-	 */
-	public String getLanguage() {
-		return language;
-	}
-
-	/**
-	 * @param language
-	 *            The language to set.
-	 */
-	public void setLanguage(String language) {
-		this.language = language;
-	}
-
-	/**
-	 * @return Returns the latitude.
-	 */
-	public double getLatitude() {
-		return latitude;
-	}
-
-	/**
-	 * @param latitude
-	 *            The latitude to set.
-	 */
-	public void setLatitude(double latitude) {
-		this.latitude = latitude;
-	}
-
-	/**
-	 * @return Returns the longitude.
-	 */
-	public double getLongitude() {
-		return longitude;
-	}
-
-	/**
-	 * @param longitude
-	 *            The longitude to set.
-	 */
-	public void setLongitude(double longitude) {
-		this.longitude = longitude;
-	}
-
-	/**
-	 * @return Returns the population.
-	 */
-	public int getPopulation() {
-		return population;
-	}
-
-	/**
-	 * @param population
-	 *            The population to set.
-	 */
-	public void setPopulation(int population) {
-		this.population = population;
-	}
-
-	/**
-	 * @return Returns the summary.
-	 */
-	public String getSummary() {
-		return summary;
-	}
-
-	/**
-	 * @param summary
-	 *            The summary to set.
-	 */
-	public void setSummary(String summary) {
-		this.summary = summary;
-	}
-
-	/**
-	 * @return Returns the title.
-	 */
-	public String getTitle() {
-		return title;
-	}
-
-	/**
-	 * @param title
-	 *            The title to set.
-	 */
-	public void setTitle(String title) {
-		this.title = title;
-	}
-
-	/**
-	 * @return Returns the wikipediaUrl.
-	 */
-	public String getWikipediaUrl() {
-		return wikipediaUrl;
-	}
-
-	/**
-	 * @param wikipediaUrl
-	 *            The wikipediaUrl to set.
-	 */
-	public void setWikipediaUrl(String wikipediaURL) {
-		this.wikipediaUrl = wikipediaURL;
-	}
-
-	/**
-	 * @return the thumbnailImg
-	 */
-	public String getThumbnailImg() {
-		return thumbnailImg;
-	}
-
-	/**
-	 * @param thumbnailImg the thumbnailImg to set
-	 */
-	public void setThumbnailImg(String thumbnailImg) {
-		this.thumbnailImg = thumbnailImg;
-	}
+    private String feature;
+
+    private int population;
+
+    private int elevation;
+
+    private double latitude;
+
+    private double longitude;
+
+    private String thumbnailImg;
+
+    /**
+     * @return Returns the elevation.
+     */
+    public int getElevation() {
+        return elevation;
+    }
+
+    /**
+     * @param elevation
+     *            The elevation to set.
+     */
+    public void setElevation(int elevation) {
+        this.elevation = elevation;
+    }
+
+    /**
+     * @return Returns the feature.
+     */
+    public String getFeature() {
+        return feature;
+    }
+
+    /**
+     * @param feature
+     *            The feature to set.
+     */
+    public void setFeature(String feature) {
+        this.feature = feature;
+    }
+
+    /**
+     * @return Returns the language.
+     */
+    public String getLanguage() {
+        return language;
+    }
+
+    /**
+     * @param language
+     *            The language to set.
+     */
+    public void setLanguage(String language) {
+        this.language = language;
+    }
+
+    /**
+     * @return Returns the latitude.
+     */
+    public double getLatitude() {
+        return latitude;
+    }
+
+    /**
+     * @param latitude
+     *            The latitude to set.
+     */
+    public void setLatitude(double latitude) {
+        this.latitude = latitude;
+    }
+
+    /**
+     * @return Returns the longitude.
+     */
+    public double getLongitude() {
+        return longitude;
+    }
+
+    /**
+     * @param longitude
+     *            The longitude to set.
+     */
+    public void setLongitude(double longitude) {
+        this.longitude = longitude;
+    }
+
+    /**
+     * @return Returns the population.
+     */
+    public int getPopulation() {
+        return population;
+    }
+
+    /**
+     * @param population
+     *            The population to set.
+     */
+    public void setPopulation(int population) {
+        this.population = population;
+    }
+
+    /**
+     * @return Returns the summary.
+     */
+    public String getSummary() {
+        return summary;
+    }
+
+    /**
+     * @param summary
+     *            The summary to set.
+     */
+    public void setSummary(String summary) {
+        this.summary = summary;
+    }
+
+    /**
+     * @return Returns the title.
+     */
+    public String getTitle() {
+        return title;
+    }
+
+    /**
+     * @param title
+     *            The title to set.
+     */
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    /**
+     * @return Returns the wikipediaUrl.
+     */
+    public String getWikipediaUrl() {
+        return wikipediaUrl;
+    }
+
+    /**
+     * @param wikipediaUrl
+     *            The wikipediaUrl to set.
+     */
+    public void setWikipediaUrl(String wikipediaURL) {
+        this.wikipediaUrl = wikipediaURL;
+    }
+
+    /**
+     * @return the thumbnailImg
+     */
+    public String getThumbnailImg() {
+        return thumbnailImg;
+    }
+
+    /**
+     * @param thumbnailImg the thumbnailImg to set
+     */
+    public void setThumbnailImg(String thumbnailImg) {
+        this.thumbnailImg = thumbnailImg;
+    }
 
 }

Modified: incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/utils/Bearing.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/utils/Bearing.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/utils/Bearing.java (original)
+++ incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/utils/Bearing.java Sun Dec 12 16:10:48 2010
@@ -24,37 +24,37 @@ import static java.lang.Math.toDegrees;
 
 /**
  * compass bearing from the first point to the second point in degrees.
- * 
+ *
  * @author Mark Thomas
  */
 public class Bearing {
 
-	/**
-	 * Returns the direction from the first point to the second point in
-	 * degrees. The direction is the clockwise angle between the magnetic north
-	 * and the direction from point1 to point2
-	 * 
-	 * @param lat1
-	 * @param lng1
-	 * @param lat2
-	 * @param lng2
-	 * @return
-	 */
-	public static double calculateBearing(double lat1, double lng1,
-			double lat2, double lng2) {
-		final double x3 = toRadians(lat1);
-		final double y3 = toRadians(lng1);
-		final double x4 = toRadians(lat2);
-		final double y4 = toRadians(lng2);
-		double numerator = (sin(y3) * sin(x4 - x3));
-		double denominator = ((sin(y4) * cos(y3)) - (cos(y4) * sin(y3) * cos(x4
-				- x3)));
-		double bearing = toDegrees(atan(numerator / denominator));
-		if (denominator > 0) {
-			bearing += 360D;
-		} else if (denominator > 0) {
-			bearing += 180;
-		}
-		return (bearing < 0 ? (bearing + 360D) : bearing);
-	}
+    /**
+     * Returns the direction from the first point to the second point in
+     * degrees. The direction is the clockwise angle between the magnetic north
+     * and the direction from point1 to point2
+     *
+     * @param lat1
+     * @param lng1
+     * @param lat2
+     * @param lng2
+     * @return
+     */
+    public static double calculateBearing(double lat1, double lng1,
+            double lat2, double lng2) {
+        final double x3 = toRadians(lat1);
+        final double y3 = toRadians(lng1);
+        final double x4 = toRadians(lat2);
+        final double y4 = toRadians(lng2);
+        double numerator = (sin(y3) * sin(x4 - x3));
+        double denominator = ((sin(y4) * cos(y3)) - (cos(y4) * sin(y3) * cos(x4
+                - x3)));
+        double bearing = toDegrees(atan(numerator / denominator));
+        if (denominator > 0) {
+            bearing += 360D;
+        } else if (denominator > 0) {
+            bearing += 180;
+        }
+        return (bearing < 0 ? (bearing + 360D) : bearing);
+    }
 }

Modified: incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/utils/Distance.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/utils/Distance.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/utils/Distance.java (original)
+++ incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/utils/Distance.java Sun Dec 12 16:10:48 2010
@@ -18,76 +18,76 @@ package org.geonames.utils;
 
 /**
  * Distance calculations.
- * 
+ *
  * @author marc@geonames
- * 
+ *
  */
 public class Distance {
 
-	/**
-	 * mean radius = 6372.0
-	 * 
-	 * The Earth's equatorial radius = 6335.437 km.
-	 * 
-	 * The Earth's polar radius = 6399.592 km.
-	 * 
-	 * 
-	 */
-	public static final double EARTH_RADIUS_KM = 6372.0;
-
-	/**
-	 * statute miles
-	 */
-	public static final double EARTH_RADIUS_MILES = 3963.0;
-
-	/**
-	 * http://mathworld.wolfram.com/GreatCircle.html
-	 * 
-	 * and
-	 * 
-	 * http://www.mathforum.com/library/drmath/view/51711.html
-	 * 
-	 * @return
-	 */
-	public static double distance(double lat1, double lng1, double lat2,
-			double lng2, char unit) {
-		double a1 = Math.toRadians(lat1);
-		double b1 = Math.toRadians(lng1);
-		double a2 = Math.toRadians(lat2);
-		double b2 = Math.toRadians(lng2);
-		double d = Math.acos(Math.cos(a1) * Math.cos(b1) * Math.cos(a2)
-				* Math.cos(b2) + Math.cos(a1) * Math.sin(b1) * Math.cos(a2)
-				* Math.sin(b2) + Math.sin(a1) * Math.sin(a2));
-
-		double dist = 0;
-		if (unit == 'M') {
-			dist = d * EARTH_RADIUS_MILES;
-		} else {
-			dist = d * EARTH_RADIUS_KM;
-		}
-
-		if (Double.isNaN(dist)) {
-			// use pytagoras for very small distances, 
-			dist = Math.sqrt(Math.pow(Math.abs(lat1 - lat2), 2)
-					+ Math.pow(Math.abs(lng1 - lng2), 2));
-			// as rule of thumb multiply with 110km =1 degree
-			if (unit == 'M') {
-				dist *= 69;
-			} else {
-				dist *= 110;
-			}
-		}
-
-		return dist;
-	}
-
-	public static double distanceKM(double lat1, double lng1, double lat2,
-			double lng2) {
-		return distance(lat1, lng1, lat2, lng2, 'K');
-	}
-
-	public static double distanceMiles(double lat1, double lng1, double lat2,
-			double lng2) {
-		return distance(lat1, lng1, lat2, lng2, 'M');
-	}
+    /**
+     * mean radius = 6372.0
+     *
+     * The Earth's equatorial radius = 6335.437 km.
+     *
+     * The Earth's polar radius = 6399.592 km.
+     *
+     *
+     */
+    public static final double EARTH_RADIUS_KM = 6372.0;
+
+    /**
+     * statute miles
+     */
+    public static final double EARTH_RADIUS_MILES = 3963.0;
+
+    /**
+     * http://mathworld.wolfram.com/GreatCircle.html
+     *
+     * and
+     *
+     * http://www.mathforum.com/library/drmath/view/51711.html
+     *
+     * @return
+     */
+    public static double distance(double lat1, double lng1, double lat2,
+            double lng2, char unit) {
+        double a1 = Math.toRadians(lat1);
+        double b1 = Math.toRadians(lng1);
+        double a2 = Math.toRadians(lat2);
+        double b2 = Math.toRadians(lng2);
+        double d = Math.acos(Math.cos(a1) * Math.cos(b1) * Math.cos(a2)
+                * Math.cos(b2) + Math.cos(a1) * Math.sin(b1) * Math.cos(a2)
+                * Math.sin(b2) + Math.sin(a1) * Math.sin(a2));
+
+        double dist = 0;
+        if (unit == 'M') {
+            dist = d * EARTH_RADIUS_MILES;
+        } else {
+            dist = d * EARTH_RADIUS_KM;
+        }
+
+        if (Double.isNaN(dist)) {
+            // use pytagoras for very small distances,
+            dist = Math.sqrt(Math.pow(Math.abs(lat1 - lat2), 2)
+                    + Math.pow(Math.abs(lng1 - lng2), 2));
+            // as rule of thumb multiply with 110km =1 degree
+            if (unit == 'M') {
+                dist *= 69;
+            } else {
+                dist *= 110;
+            }
+        }
+
+        return dist;
+    }
+
+    public static double distanceKM(double lat1, double lng1, double lat2,
+            double lng2) {
+        return distance(lat1, lng1, lat2, lng2, 'K');
+    }
+
+    public static double distanceMiles(double lat1, double lng1, double lat2,
+            double lng2) {
+        return distance(lat1, lng1, lat2, lng2, 'M');
+    }
 }

Modified: incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/wikipedia/TextSummaryExtractor.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/wikipedia/TextSummaryExtractor.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/wikipedia/TextSummaryExtractor.java (original)
+++ incubator/stanbol/trunk/fise/ext/org.geonames/src/main/java/org/geonames/wikipedia/TextSummaryExtractor.java Sun Dec 12 16:10:48 2010
@@ -18,264 +18,264 @@ package org.geonames.wikipedia;
 
 /**
  * @author marc
- * 
+ *
  */
 public class TextSummaryExtractor {
 
-	/**
-	 * extract a text summary from a wikipedia article. The wikipedia markup is
-	 * removed. The length of the summary is equal or lower the length of the
-	 * parameter. The extractor tries to end the summary at a fullstop.
-	 * 
-	 * @param pText
-	 * @param length
-	 * @return
-	 */
-	public static String extractSummary(String pText, int length) {
-		if (pText == null) {
-			return null;
-		}
-
-		// remove all wikipedia markup (paragraphs are kept)
-		//
-		StringBuilder summary = new StringBuilder();
-		int idx = 0;
-
-		// loop over all characters in input string
-		while (idx > -1 && (summary.length() < length || length == 0)
-				&& idx < pText.length()) {
-			// get next chacter
-			char c = pText.charAt(idx);
-
-			if (c == '{') {
-				// skip template and set idx to end of template
-				idx = skipTemplate(pText, idx);
-				continue;
-			} else if (c == '<') {
-				// is it a html comment
-				if (pText.length() > idx + 1 && pText.charAt(idx + 1) == '!') {
-					// skip html comment
-					idx = skipHTMLComment(pText, idx);
-					continue;
-				} else {
-					// html element starts here, skip it, set idx to end of html
-					// element
-					idx = skipHTMLElement(pText, idx);
-					continue;
-				}
-			} else if (c == '[') {
-
-				// look ahead to see whether we have a link
-				if (pText.charAt(idx + 1) == '[') {
-					// we have two square brackets "[[" (link)
-
-					// get the end of the double square bracket
-					int endOfLink = pText.indexOf("]]", idx);
-
-					// image link ?
-					int colon = pText.indexOf(":", idx);
-					if (colon > -1 && colon < endOfLink) {
-						// image link contains a caption which might contain
-						// a link within the link
-						idx = findEndOfLink(pText, idx);
-						continue;
-					}
-
-					int beginAnchor = pText.indexOf("|", idx);
-					if (beginAnchor > -1 && beginAnchor < endOfLink) {
-						idx = beginAnchor + 1;
-					} else {
-						idx = idx + 2;
-					}
-					continue;
-				} else {
-					// next character is not a square brackets and thus a
-					// reference link to be removed
-					// get the end of the square bracket
-					int endOfLink = pText.indexOf("]", idx);
-					if (endOfLink > -1) {
-						idx = endOfLink + 1;
-						continue;
-					}
-				}
-			} else if (c == ']') {
-				// look ahead
-				if (idx + 1 < pText.length() && pText.charAt(idx + 1) == ']') {
-					idx = idx + 2;
-					continue;
-				}
-			}
-
-			summary.append(c);
-			idx++;
-		}
-
-		String textString = removeIndentAtBeginning(summary.toString());
-		textString = removeWhiteSpace(
-				textString.replaceAll("\r", " ").replaceAll("\n", " ")
-						.replaceAll("\t", " ")).trim();
-		textString = removeBold(textString);
-		textString = removeItalic(textString);
-
-		// convert 'non breaking html spaces' into blanks. But preserve them
-		// (don't remove white space)
-		textString = textString.replaceAll("&nbsp;", " ");
-
-		// find full stop near length of text
-		// only look at first paragraph for summary
-		int endOfTextIdx = textString.indexOf("==");
-		if (endOfTextIdx == -1) {
-			endOfTextIdx = length;
-		}
-
-		// 
-		if (endOfTextIdx < 20 || endOfTextIdx > length) {
-			endOfTextIdx = textString.lastIndexOf(".");
-			if (endOfTextIdx < 0.7 * length) {
-				endOfTextIdx = textString.lastIndexOf(" ");
-			}
-		}
-
-		// add elipsis if we have shortened the article
-		if (endOfTextIdx > -1 && endOfTextIdx < textString.length()) {
-			textString = textString.substring(0, endOfTextIdx) + " (...)";
-		}
-
-		// trim trailing spaces and return
-		return textString.trim();
-	}
-
-	/**
-	 * skips templates in wikipedia markup. Templates are enclosed within braces
-	 * {}. There might be nested templates within an other template.
-	 * 
-	 * @param pText
-	 *            : the wikipedia text with templates
-	 * @param pIdx
-	 *            , pos in text to start with, MUST be a {
-	 * @return the idx into the text where the template ends, or the last
-	 *         character in the text if it does not properly end.
-	 */
-	static int skipTemplate(String pText, int pIdx) {
-		// make sure we start with opening braces
-		if (pText.charAt(pIdx) != '{') {
-			return pIdx;
-		}
-
-		// counter for the braces we have opened, braces might be recursive
-		// we use an iterative implementation, since it is a tiny little bit
-		// faster
-		int numOpenings = 1;
-		// start with the next character
-		int idx = pIdx + 1;
-		// loop over the text starting from the next character till the end of
-		// the template or the end of the text
-		while (numOpenings > 0 && pText.length() > idx) {
-			if (pText.charAt(idx) == '{') {
-				numOpenings++;
-			} else if (pText.charAt(idx) == '}') {
-				numOpenings--;
-			}
-			idx++;
-		}
-		return idx;
-	}
-
-	/**
-	 * @param pText
-	 * @param pIdx
-	 *            , pos in text to start with, MUST be a {
-	 * @return
-	 */
-	static int skipHTMLElement(String pText, int pIdx) {
-		if (pText.charAt(pIdx) != '<') {
-			return pIdx;
-		}
-
-		int numOpenings = 1;
-		int idx = pIdx + 1;
-		while (numOpenings > 0 && pText.length() > idx) {
-			if (pText.charAt(idx) == '<') {
-				numOpenings++;
-			} else if (pText.charAt(idx) == '>') {
-				numOpenings--;
-			}
-			idx++;
-		}
-		return idx;
-	}
+    /**
+     * extract a text summary from a wikipedia article. The wikipedia markup is
+     * removed. The length of the summary is equal or lower the length of the
+     * parameter. The extractor tries to end the summary at a fullstop.
+     *
+     * @param pText
+     * @param length
+     * @return
+     */
+    public static String extractSummary(String pText, int length) {
+        if (pText == null) {
+            return null;
+        }
+
+        // remove all wikipedia markup (paragraphs are kept)
+        //
+        StringBuilder summary = new StringBuilder();
+        int idx = 0;
+
+        // loop over all characters in input string
+        while (idx > -1 && (summary.length() < length || length == 0)
+                && idx < pText.length()) {
+            // get next chacter
+            char c = pText.charAt(idx);
+
+            if (c == '{') {
+                // skip template and set idx to end of template
+                idx = skipTemplate(pText, idx);
+                continue;
+            } else if (c == '<') {
+                // is it a html comment
+                if (pText.length() > idx + 1 && pText.charAt(idx + 1) == '!') {
+                    // skip html comment
+                    idx = skipHTMLComment(pText, idx);
+                    continue;
+                } else {
+                    // html element starts here, skip it, set idx to end of html
+                    // element
+                    idx = skipHTMLElement(pText, idx);
+                    continue;
+                }
+            } else if (c == '[') {
+
+                // look ahead to see whether we have a link
+                if (pText.charAt(idx + 1) == '[') {
+                    // we have two square brackets "[[" (link)
+
+                    // get the end of the double square bracket
+                    int endOfLink = pText.indexOf("]]", idx);
+
+                    // image link ?
+                    int colon = pText.indexOf(":", idx);
+                    if (colon > -1 && colon < endOfLink) {
+                        // image link contains a caption which might contain
+                        // a link within the link
+                        idx = findEndOfLink(pText, idx);
+                        continue;
+                    }
+
+                    int beginAnchor = pText.indexOf("|", idx);
+                    if (beginAnchor > -1 && beginAnchor < endOfLink) {
+                        idx = beginAnchor + 1;
+                    } else {
+                        idx = idx + 2;
+                    }
+                    continue;
+                } else {
+                    // next character is not a square brackets and thus a
+                    // reference link to be removed
+                    // get the end of the square bracket
+                    int endOfLink = pText.indexOf("]", idx);
+                    if (endOfLink > -1) {
+                        idx = endOfLink + 1;
+                        continue;
+                    }
+                }
+            } else if (c == ']') {
+                // look ahead
+                if (idx + 1 < pText.length() && pText.charAt(idx + 1) == ']') {
+                    idx = idx + 2;
+                    continue;
+                }
+            }
+
+            summary.append(c);
+            idx++;
+        }
+
+        String textString = removeIndentAtBeginning(summary.toString());
+        textString = removeWhiteSpace(
+                textString.replaceAll("\r", " ").replaceAll("\n", " ")
+                        .replaceAll("\t", " ")).trim();
+        textString = removeBold(textString);
+        textString = removeItalic(textString);
+
+        // convert 'non breaking html spaces' into blanks. But preserve them
+        // (don't remove white space)
+        textString = textString.replaceAll("&nbsp;", " ");
+
+        // find full stop near length of text
+        // only look at first paragraph for summary
+        int endOfTextIdx = textString.indexOf("==");
+        if (endOfTextIdx == -1) {
+            endOfTextIdx = length;
+        }
+
+        //
+        if (endOfTextIdx < 20 || endOfTextIdx > length) {
+            endOfTextIdx = textString.lastIndexOf(".");
+            if (endOfTextIdx < 0.7 * length) {
+                endOfTextIdx = textString.lastIndexOf(" ");
+            }
+        }
+
+        // add elipsis if we have shortened the article
+        if (endOfTextIdx > -1 && endOfTextIdx < textString.length()) {
+            textString = textString.substring(0, endOfTextIdx) + " (...)";
+        }
+
+        // trim trailing spaces and return
+        return textString.trim();
+    }
+
+    /**
+     * skips templates in wikipedia markup. Templates are enclosed within braces
+     * {}. There might be nested templates within an other template.
+     *
+     * @param pText
+     *            : the wikipedia text with templates
+     * @param pIdx
+     *            , pos in text to start with, MUST be a {
+     * @return the idx into the text where the template ends, or the last
+     *         character in the text if it does not properly end.
+     */
+    static int skipTemplate(String pText, int pIdx) {
+        // make sure we start with opening braces
+        if (pText.charAt(pIdx) != '{') {
+            return pIdx;
+        }
+
+        // counter for the braces we have opened, braces might be recursive
+        // we use an iterative implementation, since it is a tiny little bit
+        // faster
+        int numOpenings = 1;
+        // start with the next character
+        int idx = pIdx + 1;
+        // loop over the text starting from the next character till the end of
+        // the template or the end of the text
+        while (numOpenings > 0 && pText.length() > idx) {
+            if (pText.charAt(idx) == '{') {
+                numOpenings++;
+            } else if (pText.charAt(idx) == '}') {
+                numOpenings--;
+            }
+            idx++;
+        }
+        return idx;
+    }
+
+    /**
+     * @param pText
+     * @param pIdx
+     *            , pos in text to start with, MUST be a {
+     * @return
+     */
+    static int skipHTMLElement(String pText, int pIdx) {
+        if (pText.charAt(pIdx) != '<') {
+            return pIdx;
+        }
+
+        int numOpenings = 1;
+        int idx = pIdx + 1;
+        while (numOpenings > 0 && pText.length() > idx) {
+            if (pText.charAt(idx) == '<') {
+                numOpenings++;
+            } else if (pText.charAt(idx) == '>') {
+                numOpenings--;
+            }
+            idx++;
+        }
+        return idx;
+    }
 
 /**
-	 * @param pText
-	 * @param pIdx,
-	 *            pos in text to start with, MUST be a '<'
-	 * @return
-	 */
-	static int skipHTMLComment(String pText, int pIdx) {
-		if (pText.charAt(pIdx) != '<' && pText.charAt(pIdx + 1) != '!') {
-			return pIdx;
-		}
-
-		int idx = pIdx;
-		while ((idx = pText.indexOf('-', idx)) > -1) {
-			if (pText.length() < idx + 2) {
-				return pText.length();
-			}
-			if (pText.charAt(idx) == '-' && pText.charAt(idx + 1) == '-'
-					&& pText.charAt(idx + 2) == '>') {
-				return idx + 3;
-			}
-			idx++;
-		}
-		return idx;
-	}
-
-	private static String removeIndentAtBeginning(String pText) {
-		pText = pText.trim();
-		if (pText.startsWith(":")) {
-			int lineFeed = pText.indexOf("\n");
-			if (lineFeed > -1) {
-				pText = pText.substring(lineFeed + 1);
-			} else {
-				// we may already have removed the linefeed
-				// check for italics
-				if (pText.startsWith(":''")) {
-					int italic = pText.indexOf("''", 3);
-					if (italic > -1) {
-						pText = pText.substring(italic + 2);
-					}
-				}
-			}
-		}
-		return pText;
-	}
-
-	private static int findEndOfLink(String pText, int pIdx) {
-		int end = pText.indexOf("]]", pIdx);
-		if (end == -1) {
-			return pIdx;
-		}
-
-		int idx = pIdx;
-		int openingIdx = pText.indexOf("[[", idx + 2);
-		while (openingIdx > -1 && openingIdx < end) {
-			idx = end;
-			end = pText.indexOf("]]", end + 2);
-			openingIdx = pText.indexOf("[[", idx);
-		}
-		if (end != -1) {
-			idx = end;
-		}
-		return idx;
-	}
-
-	/**
-	 * Removes sequences of whitespace and keeps only one whitespace character.
-	 */
-	public static String removeWhiteSpace(String pString) {
+     * @param pText
+     * @param pIdx,
+     *            pos in text to start with, MUST be a '<'
+     * @return
+     */
+    static int skipHTMLComment(String pText, int pIdx) {
+        if (pText.charAt(pIdx) != '<' && pText.charAt(pIdx + 1) != '!') {
+            return pIdx;
+        }
+
+        int idx = pIdx;
+        while ((idx = pText.indexOf('-', idx)) > -1) {
+            if (pText.length() < idx + 2) {
+                return pText.length();
+            }
+            if (pText.charAt(idx) == '-' && pText.charAt(idx + 1) == '-'
+                    && pText.charAt(idx + 2) == '>') {
+                return idx + 3;
+            }
+            idx++;
+        }
+        return idx;
+    }
+
+    private static String removeIndentAtBeginning(String pText) {
+        pText = pText.trim();
+        if (pText.startsWith(":")) {
+            int lineFeed = pText.indexOf("\n");
+            if (lineFeed > -1) {
+                pText = pText.substring(lineFeed + 1);
+            } else {
+                // we may already have removed the linefeed
+                // check for italics
+                if (pText.startsWith(":''")) {
+                    int italic = pText.indexOf("''", 3);
+                    if (italic > -1) {
+                        pText = pText.substring(italic + 2);
+                    }
+                }
+            }
+        }
+        return pText;
+    }
+
+    private static int findEndOfLink(String pText, int pIdx) {
+        int end = pText.indexOf("]]", pIdx);
+        if (end == -1) {
+            return pIdx;
+        }
+
+        int idx = pIdx;
+        int openingIdx = pText.indexOf("[[", idx + 2);
+        while (openingIdx > -1 && openingIdx < end) {
+            idx = end;
+            end = pText.indexOf("]]", end + 2);
+            openingIdx = pText.indexOf("[[", idx);
+        }
+        if (end != -1) {
+            idx = end;
+        }
+        return idx;
+    }
+
+    /**
+     * Removes sequences of whitespace and keeps only one whitespace character.
+     */
+    public static String removeWhiteSpace(String pString) {
         StringBuilder buf = new StringBuilder();
-		char[] chars = pString.toCharArray();
-		int counter = 0;
+        char[] chars = pString.toCharArray();
+        int counter = 0;
         for (char c : chars) {
             if (c == ' ') {
                 if (counter == 0) {
@@ -287,15 +287,15 @@ public class TextSummaryExtractor {
                 counter = 0;
             }
         }
-		return buf.toString();
-	}
+        return buf.toString();
+    }
 
-	public static String removeBold(String pString) {
-		return pString.replaceAll("'''", "");
-	}
-
-	public static String removeItalic(String pString) {
-		return pString.replaceAll("''", "");
-	}
+    public static String removeBold(String pString) {
+        return pString.replaceAll("'''", "");
+    }
+
+    public static String removeItalic(String pString) {
+        return pString.replaceAll("''", "");
+    }
 
 }

Modified: incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java (original)
+++ incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java Sun Dec 12 16:10:48 2010
@@ -9,7 +9,6 @@ import org.geonames.Toponym;
 import org.geonames.ToponymSearchCriteria;
 import org.geonames.ToponymSearchResult;
 import org.geonames.WebService;
-import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,59 +25,59 @@ import static org.junit.Assert.assertTru
  * @author Rupert Westenthaler
  */
 public class TestScore {
-	
-	private static final Logger log = LoggerFactory.getLogger(TestScore.class);
-	
-	@Test
-	public void testSearch() throws Exception {
-		ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria();
-		searchCriteria.setName("Zealand");
-		searchCriteria.setStyle(Style.FULL);
-		searchCriteria.setMaxRows(5);
-		try {
-			ToponymSearchResult searchResult = WebService.search(searchCriteria);
-			int i = 0;
-			for (Toponym toponym : searchResult.getToponyms()) {
-				i++;
-				log.info("Result "+i+" "+ toponym.getGeoNameId()+" score= "+toponym.getScore());
+
+    private static final Logger log = LoggerFactory.getLogger(TestScore.class);
+
+    @Test
+    public void testSearch() throws Exception {
+        ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria();
+        searchCriteria.setName("Zealand");
+        searchCriteria.setStyle(Style.FULL);
+        searchCriteria.setMaxRows(5);
+        try {
+            ToponymSearchResult searchResult = WebService.search(searchCriteria);
+            int i = 0;
+            for (Toponym toponym : searchResult.getToponyms()) {
+                i++;
+                log.info("Result "+i+" "+ toponym.getGeoNameId()+" score= "+toponym.getScore());
                 assertNotNull(toponym.getScore());
-				assertTrue(toponym.getScore() >= Double.valueOf(0));
-				assertTrue(toponym.getScore()<= Double.valueOf(100));
-			}
-		} catch(IOException e){
-			if (e instanceof UnknownHostException) {
-				log.warn("Unable to test LocationEnhancemetEngine when offline! -> skipping this test",e.getCause());
-			} else if (e instanceof SocketTimeoutException){
-				log.warn("Seams like the geonames.org webservice is currently unavailable -> skipping this test",e.getCause());
-			} else {
-				throw e;
-			}
-		}
-	}
-	
-	@Test
-	public void testHierarchy() throws Exception {
-		ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria();
-		searchCriteria.setName("New York");
-		searchCriteria.setStyle(Style.FULL);
-		searchCriteria.setMaxRows(1);
-		try {
-			ToponymSearchResult searchResult = WebService.search(searchCriteria);
-			int testGeonamesId = searchResult.getToponyms().iterator().next().getGeoNameId();
-		    for (Toponym hierarchy : WebService.hierarchy(testGeonamesId, null, Style.FULL)){
-		    	//this service does not provide an score, so test if 1.0 is returned
+                assertTrue(toponym.getScore() >= Double.valueOf(0));
+                assertTrue(toponym.getScore()<= Double.valueOf(100));
+            }
+        } catch(IOException e){
+            if (e instanceof UnknownHostException) {
+                log.warn("Unable to test LocationEnhancemetEngine when offline! -> skipping this test",e.getCause());
+            } else if (e instanceof SocketTimeoutException){
+                log.warn("Seams like the geonames.org webservice is currently unavailable -> skipping this test",e.getCause());
+            } else {
+                throw e;
+            }
+        }
+    }
+
+    @Test
+    public void testHierarchy() throws Exception {
+        ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria();
+        searchCriteria.setName("New York");
+        searchCriteria.setStyle(Style.FULL);
+        searchCriteria.setMaxRows(1);
+        try {
+            ToponymSearchResult searchResult = WebService.search(searchCriteria);
+            int testGeonamesId = searchResult.getToponyms().iterator().next().getGeoNameId();
+            for (Toponym hierarchy : WebService.hierarchy(testGeonamesId, null, Style.FULL)){
+                //this service does not provide an score, so test if 1.0 is returned
                 assertNotNull(hierarchy.getScore());
                 assertEquals(hierarchy.getScore(), Double.valueOf(1.0));
-		    }
-		} catch(IOException e){
-			if (e instanceof UnknownHostException) {
-				log.warn("Unable to test LocationEnhancemetEngine when offline! -> skipping this test",e.getCause());
-			} else if (e instanceof SocketTimeoutException){
-				log.warn("Seams like the geonames.org webservice is currently unavailable -> skipping this test",e.getCause());
-			} else {
-				throw e;
-			}
-		}
-	}
+            }
+        } catch(IOException e){
+            if (e instanceof UnknownHostException) {
+                log.warn("Unable to test LocationEnhancemetEngine when offline! -> skipping this test",e.getCause());
+            } else if (e instanceof SocketTimeoutException){
+                log.warn("Seams like the geonames.org webservice is currently unavailable -> skipping this test",e.getCause());
+            } else {
+                throw e;
+            }
+        }
+    }
 
 }

Modified: incubator/stanbol/trunk/fise/generic/jobmanager/src/main/java/eu/iksproject/fise/jobmanager/impl/InMemoryJobManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/generic/jobmanager/src/main/java/eu/iksproject/fise/jobmanager/impl/InMemoryJobManager.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/generic/jobmanager/src/main/java/eu/iksproject/fise/jobmanager/impl/InMemoryJobManager.java (original)
+++ incubator/stanbol/trunk/fise/generic/jobmanager/src/main/java/eu/iksproject/fise/jobmanager/impl/InMemoryJobManager.java Sun Dec 12 16:10:48 2010
@@ -50,10 +50,10 @@ public class InMemoryJobManager implemen
         //however the remove Method will not have any affect if the list was
         //changed.
         synchronized (sortedEngineList) {
-        	engines = sortedEngineList.iterator();
-		}
+            engines = sortedEngineList.iterator();
+        }
         while (engines.hasNext()) {
-        	EnhancementEngine engine = engines.next();
+            EnhancementEngine engine = engines.next();
             if (engine.canEnhance(ci) == EnhancementEngine.CANNOT_ENHANCE) {
                 log.debug("[{}] cannot be enhanced by engine [{}], skipping",
                         ci.getId(), engine);
@@ -91,25 +91,25 @@ public class InMemoryJobManager implemen
 
     private static class ExecutionOrderComparator implements Comparator<EnhancementEngine> {
 
-		@Override
-		public int compare(EnhancementEngine engine1, EnhancementEngine engine2) {
-			Integer order1 = getOrder(engine1);
-			Integer order2 = getOrder(engine2);
-			//start with the highest number finish with the lowest ...
-			return order1 == order2?0:order1<order2?1:-1;
-		}
-
-		public Integer getOrder(EnhancementEngine engine){
-			log.info("getOrder "+engine);
-			if (engine instanceof ServiceProperties){
-				log.info(" ... implements ServiceProperties");
-				Object value = ((ServiceProperties)engine).getServiceProperties().get(ServiceProperties.ENHANCEMENT_ENGINE_ORDERING);
-				log.info("   > value = "+value +" "+value.getClass());
-				if (value !=null && value instanceof Integer){
-					return (Integer)value;
-				}
-			}
-			return ServiceProperties.ORDERING_DEFAULT;
-		}
+        @Override
+        public int compare(EnhancementEngine engine1, EnhancementEngine engine2) {
+            Integer order1 = getOrder(engine1);
+            Integer order2 = getOrder(engine2);
+            //start with the highest number finish with the lowest ...
+            return order1 == order2?0:order1<order2?1:-1;
+        }
+
+        public Integer getOrder(EnhancementEngine engine){
+            log.info("getOrder "+engine);
+            if (engine instanceof ServiceProperties){
+                log.info(" ... implements ServiceProperties");
+                Object value = ((ServiceProperties)engine).getServiceProperties().get(ServiceProperties.ENHANCEMENT_ENGINE_ORDERING);
+                log.info("   > value = "+value +" "+value.getClass());
+                if (value !=null && value instanceof Integer){
+                    return (Integer)value;
+                }
+            }
+            return ServiceProperties.ORDERING_DEFAULT;
+        }
     }
-}
\ No newline at end of file
+}

Modified: incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonComparator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonComparator.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonComparator.java (original)
+++ incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonComparator.java Sun Dec 12 16:10:48 2010
@@ -5,15 +5,15 @@ import java.util.Comparator;
 /**
  * A comparator for JSON-LD maps to ensure the order of certain key elements
  * like '#', '@', 'a' in JSON-LD output.
- * 
+ *
  * @author Fabian Christ
  */
 public class JsonComparator implements Comparator<Object> {
 
-	@Override
-	public int compare(Object arg0, Object arg1) {
-		int value;
-		if (arg0.equals(arg1)) {
+    @Override
+    public int compare(Object arg0, Object arg1) {
+        int value;
+        if (arg0.equals(arg1)) {
             value = 0;
         } else if (arg0.equals("#")) {
             value = -1;
@@ -38,8 +38,8 @@ public class JsonComparator implements C
         } else {
             value = String.valueOf(arg0).toLowerCase().compareTo(String.valueOf(arg1).toLowerCase());
         }
-		
-		return value;
-	}
+
+        return value;
+    }
 
 }

Modified: incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonLd.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonLd.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonLd.java (original)
+++ incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonLd.java Sun Dec 12 16:10:48 2010
@@ -10,304 +10,304 @@ import java.util.TreeMap;
 
 /**
  * @author Fabian Christ
- * 
+ *
  */
 public class JsonLd {
 
-	// Map Namespace -> Prefix
-	private Map<String, String> namespacePrefixMap = new HashMap<String, String>();
+    // Map Namespace -> Prefix
+    private Map<String, String> namespacePrefixMap = new HashMap<String, String>();
 
-	// Map Subject -> Resource
-	private Map<String, JsonLdResource> resourceMap = new TreeMap<String, JsonLdResource>(new JsonComparator());
+    // Map Subject -> Resource
+    private Map<String, JsonLdResource> resourceMap = new TreeMap<String, JsonLdResource>(new JsonComparator());
 
-	/**
-	 * Flag to control whether the namespace prefix map should be used
-	 * to shorten IRIs to prefix notation during serialization. Default
-	 * value is <code>true</code>.<br />
-	 * <br />
-	 * If you already put values into this JSON-LD instance with prefix
-	 * notation, you should set this to <code>false</code> before starting
-	 * the serialization.
-	 */
-	private boolean applyNamespaces = true;
-	
-	/**
-	 * Flag to control whether the serialized JSON-LD output will use
-	 * joint or disjoint graphs for subjects and namespaces.  Default
-	 * value is <code>true</code>.
-	 */
-	private boolean useJointGraphs = true;
-	
-	/**
-	 * Add the given resource to this JsonLd object using the resourceId
-	 * as key.
-	 * 
-	 * @param resourceId
-	 * @param resource
-	 */
-	public void put(String resourceId, JsonLdResource resource) {
-		this.resourceMap.put(resourceId, resource);
-	}
-
-	@Override
-	public String toString() {
-		if (useJointGraphs) {
-			Map<String, Object> json = createJointGraph();
-			
-			return JsonSerializer.toString(json);
-		}
-		else {
-			List<Object> json = createDisjointGraph();
-			
-			return JsonSerializer.toString(json);
-		}
-	}
-	
-	public String toString(int indent) {
-		if (useJointGraphs) {
-			Map<String, Object> json = createJointGraph();
-			
-			return JsonSerializer.toString(json, indent);
-		}
-		else {
-			List<Object> json = createDisjointGraph();
-			
-			return JsonSerializer.toString(json, indent);
-		}
-	}
-	
-	private List<Object> createDisjointGraph() {
-		List<Object> json = new ArrayList<Object>();
-		if (!resourceMap.isEmpty()) {
-
-			for (String subject : resourceMap.keySet()) {
-				Map<String, Object> subjectObject = new TreeMap<String, Object>(new JsonComparator());
-
-				// put the namespaces
-				if (!namespacePrefixMap.isEmpty()) {
-					Map<String, Object> nsObject = new TreeMap<String, Object>(new JsonComparator());
-					for (String ns : namespacePrefixMap.keySet()) {
-						nsObject.put(namespacePrefixMap.get(ns), ns);
-					}
-					subjectObject.put("#", nsObject);
-				}
-
-				JsonLdResource resource = resourceMap.get(subject);
-
-				// put subject
-				if (resource.getSubject() != null) {
-					subjectObject.put("@", resource.getSubject());
-				}
-				
-				// put types
-				putTypes(subjectObject, resource);
-
-				// put properties = objects
-				putProperties(subjectObject, resource);
-
-				// add to list of subjects
-				json.add(subjectObject);
-			}
-
-		}
-		
-		return json;
-	}
-
-	@SuppressWarnings("unchecked")
-	private Map<String, Object> createJointGraph() {
-		Map<String, Object> json = new TreeMap<String, Object>(new JsonComparator());
-		if (!resourceMap.isEmpty()) {
-			List<Object> subjects = new ArrayList<Object>();
-
-			for (String subject : resourceMap.keySet()) {
-				// put subject
-				Map<String, Object> subjectObject = new TreeMap<String, Object>(new JsonComparator());
-
-				JsonLdResource resource = resourceMap.get(subject);
-
-				// put subject
-				if (resource.getSubject() != null) {
-					subjectObject.put("@", resource.getSubject());
-				}
-				
-				// put types
-				putTypes(subjectObject, resource);
-
-				// put properties = objects
-				putProperties(subjectObject, resource);
-
-				// add to list of subjects
-				subjects.add(subjectObject);
-			}
-
-			// put subjects
-			if (!subjects.isEmpty()) {
-				if (subjects.size() == 1) {
-					json = (Map<String, Object>) subjects.get(0);
-				} else {
-					json.put("@", subjects);
-				}
-			}
-		}
-
-		// put the namespaces
-		if (!namespacePrefixMap.isEmpty()) {
-			Map<String, Object> nsObject = new TreeMap<String, Object>(new JsonComparator());
-			for (String ns : namespacePrefixMap.keySet()) {
-				nsObject.put(namespacePrefixMap.get(ns), ns);
-			}
-			json.put("#", nsObject);
-		}
-
-		return json;
-	}
-
-	private void putTypes(Map<String, Object> subjectObject, JsonLdResource resource) {
-		if (!resource.getTypes().isEmpty()) {
-			List<String> types = new ArrayList<String>();
-			for (String type : resource.getTypes()) {
-				types.add(applyNamespace(type));
-			}
-			if (types.size() == 1) {
-				subjectObject.put("a", types.get(0));
-			}
-			else {
-				Collections.sort(types, new Comparator<String>() {
-
-					@Override
-					public int compare(String arg0, String arg1) {
-						return arg0.compareTo(arg1);
-					}
-
-				});
-				subjectObject.put("a", types);
-			}
-		}
-	}
-	
-	private void putProperties(Map<String, Object> jsonObject, JsonLdResource resource) {
-		for (String property : resource.getPropertyMap().keySet()) {
-			Object value = resource.getPropertyMap().get(property);
-			if (value instanceof String) {
-				value = applyNamespace((String) value);
-				jsonObject.put(applyNamespace(property), value);
-			}
-			else if (value instanceof String[]) {
-				String[] stringArray = (String[]) value;
-				List<String> valueList = new ArrayList<String>();
+    /**
+     * Flag to control whether the namespace prefix map should be used
+     * to shorten IRIs to prefix notation during serialization. Default
+     * value is <code>true</code>.<br />
+     * <br />
+     * If you already put values into this JSON-LD instance with prefix
+     * notation, you should set this to <code>false</code> before starting
+     * the serialization.
+     */
+    private boolean applyNamespaces = true;
+
+    /**
+     * Flag to control whether the serialized JSON-LD output will use
+     * joint or disjoint graphs for subjects and namespaces.  Default
+     * value is <code>true</code>.
+     */
+    private boolean useJointGraphs = true;
+
+    /**
+     * Add the given resource to this JsonLd object using the resourceId
+     * as key.
+     *
+     * @param resourceId
+     * @param resource
+     */
+    public void put(String resourceId, JsonLdResource resource) {
+        this.resourceMap.put(resourceId, resource);
+    }
+
+    @Override
+    public String toString() {
+        if (useJointGraphs) {
+            Map<String, Object> json = createJointGraph();
+
+            return JsonSerializer.toString(json);
+        }
+        else {
+            List<Object> json = createDisjointGraph();
+
+            return JsonSerializer.toString(json);
+        }
+    }
+
+    public String toString(int indent) {
+        if (useJointGraphs) {
+            Map<String, Object> json = createJointGraph();
+
+            return JsonSerializer.toString(json, indent);
+        }
+        else {
+            List<Object> json = createDisjointGraph();
+
+            return JsonSerializer.toString(json, indent);
+        }
+    }
+
+    private List<Object> createDisjointGraph() {
+        List<Object> json = new ArrayList<Object>();
+        if (!resourceMap.isEmpty()) {
+
+            for (String subject : resourceMap.keySet()) {
+                Map<String, Object> subjectObject = new TreeMap<String, Object>(new JsonComparator());
+
+                // put the namespaces
+                if (!namespacePrefixMap.isEmpty()) {
+                    Map<String, Object> nsObject = new TreeMap<String, Object>(new JsonComparator());
+                    for (String ns : namespacePrefixMap.keySet()) {
+                        nsObject.put(namespacePrefixMap.get(ns), ns);
+                    }
+                    subjectObject.put("#", nsObject);
+                }
+
+                JsonLdResource resource = resourceMap.get(subject);
+
+                // put subject
+                if (resource.getSubject() != null) {
+                    subjectObject.put("@", resource.getSubject());
+                }
+
+                // put types
+                putTypes(subjectObject, resource);
+
+                // put properties = objects
+                putProperties(subjectObject, resource);
+
+                // add to list of subjects
+                json.add(subjectObject);
+            }
+
+        }
+
+        return json;
+    }
+
+    @SuppressWarnings("unchecked")
+    private Map<String, Object> createJointGraph() {
+        Map<String, Object> json = new TreeMap<String, Object>(new JsonComparator());
+        if (!resourceMap.isEmpty()) {
+            List<Object> subjects = new ArrayList<Object>();
+
+            for (String subject : resourceMap.keySet()) {
+                // put subject
+                Map<String, Object> subjectObject = new TreeMap<String, Object>(new JsonComparator());
+
+                JsonLdResource resource = resourceMap.get(subject);
+
+                // put subject
+                if (resource.getSubject() != null) {
+                    subjectObject.put("@", resource.getSubject());
+                }
+
+                // put types
+                putTypes(subjectObject, resource);
+
+                // put properties = objects
+                putProperties(subjectObject, resource);
+
+                // add to list of subjects
+                subjects.add(subjectObject);
+            }
+
+            // put subjects
+            if (!subjects.isEmpty()) {
+                if (subjects.size() == 1) {
+                    json = (Map<String, Object>) subjects.get(0);
+                } else {
+                    json.put("@", subjects);
+                }
+            }
+        }
+
+        // put the namespaces
+        if (!namespacePrefixMap.isEmpty()) {
+            Map<String, Object> nsObject = new TreeMap<String, Object>(new JsonComparator());
+            for (String ns : namespacePrefixMap.keySet()) {
+                nsObject.put(namespacePrefixMap.get(ns), ns);
+            }
+            json.put("#", nsObject);
+        }
+
+        return json;
+    }
+
+    private void putTypes(Map<String, Object> subjectObject, JsonLdResource resource) {
+        if (!resource.getTypes().isEmpty()) {
+            List<String> types = new ArrayList<String>();
+            for (String type : resource.getTypes()) {
+                types.add(applyNamespace(type));
+            }
+            if (types.size() == 1) {
+                subjectObject.put("a", types.get(0));
+            }
+            else {
+                Collections.sort(types, new Comparator<String>() {
+
+                    @Override
+                    public int compare(String arg0, String arg1) {
+                        return arg0.compareTo(arg1);
+                    }
+
+                });
+                subjectObject.put("a", types);
+            }
+        }
+    }
+
+    private void putProperties(Map<String, Object> jsonObject, JsonLdResource resource) {
+        for (String property : resource.getPropertyMap().keySet()) {
+            Object value = resource.getPropertyMap().get(property);
+            if (value instanceof String) {
+                value = applyNamespace((String) value);
+                jsonObject.put(applyNamespace(property), value);
+            }
+            else if (value instanceof String[]) {
+                String[] stringArray = (String[]) value;
+                List<String> valueList = new ArrayList<String>();
                 for (String uri : stringArray) {
                     valueList.add(applyNamespace(uri));
                 }
-				List<Object> jsonArray = new ArrayList<Object>(valueList);
-				jsonObject.put(applyNamespace(property), jsonArray);
-			}
-			else if (value instanceof Object[]) {
-				Object[] objectArray = (Object[]) value;
-				List<Object> jsonArray = new ArrayList<Object>();
-				for (Object object : objectArray) {
-					jsonArray.add(object);
-				}
-				jsonObject.put(applyNamespace(property), jsonArray);
-			}
-			else {
-				jsonObject.put(applyNamespace(property), value);
-			}
-		}
-	}
-
-	private String applyNamespace(String uri) {
-		if (applyNamespaces) {
-			for (String namespace : namespacePrefixMap.keySet()) {
-				String prefix = namespacePrefixMap.get(namespace) + ":";
-				uri = uri.replaceAll(namespace, prefix);
-			}
-		}
-		return uri;
-	}
-
-	/**
-	 * Return the JSON-LD Resource for the given subject.
-	 */
-	public JsonLdResource getResource(String subject) {
-		return resourceMap.get(subject);
-	}
-
-	/**
-	 * Get the known namespace to prefix mapping.
-	 * 
-	 * @return A {@link Map} from namespace String to prefix String.
-	 */
-	public Map<String, String> getNamespacePrefixMap() {
-		return namespacePrefixMap;
-	}
-
-	/**
-	 * Sets the known namespaces for the serializer.
-	 * 
-	 * @param namespacePrefixMap
-	 *            A {@link Map} from namespace String to prefix
-	 *            String.
-	 */
-	public void setNamespacePrefixMap(Map<String, String> namespacePrefixMap) {
-		this.namespacePrefixMap = namespacePrefixMap;
-	}
-
-	/**
-	 * Adds a new namespace and its prefix to the list of used namespaces for this
-	 * JSON-LD instance.
-	 * 
-	 * @param namespace A namespace IRI.
-	 * @param prefix A prefix to use and identify this namespace in serialized JSON-LD.
-	 */
-	public void addNamespacePrefix(String namespace, String prefix) {
+                List<Object> jsonArray = new ArrayList<Object>(valueList);
+                jsonObject.put(applyNamespace(property), jsonArray);
+            }
+            else if (value instanceof Object[]) {
+                Object[] objectArray = (Object[]) value;
+                List<Object> jsonArray = new ArrayList<Object>();
+                for (Object object : objectArray) {
+                    jsonArray.add(object);
+                }
+                jsonObject.put(applyNamespace(property), jsonArray);
+            }
+            else {
+                jsonObject.put(applyNamespace(property), value);
+            }
+        }
+    }
+
+    private String applyNamespace(String uri) {
+        if (applyNamespaces) {
+            for (String namespace : namespacePrefixMap.keySet()) {
+                String prefix = namespacePrefixMap.get(namespace) + ":";
+                uri = uri.replaceAll(namespace, prefix);
+            }
+        }
+        return uri;
+    }
+
+    /**
+     * Return the JSON-LD Resource for the given subject.
+     */
+    public JsonLdResource getResource(String subject) {
+        return resourceMap.get(subject);
+    }
+
+    /**
+     * Get the known namespace to prefix mapping.
+     *
+     * @return A {@link Map} from namespace String to prefix String.
+     */
+    public Map<String, String> getNamespacePrefixMap() {
+        return namespacePrefixMap;
+    }
+
+    /**
+     * Sets the known namespaces for the serializer.
+     *
+     * @param namespacePrefixMap
+     *            A {@link Map} from namespace String to prefix
+     *            String.
+     */
+    public void setNamespacePrefixMap(Map<String, String> namespacePrefixMap) {
+        this.namespacePrefixMap = namespacePrefixMap;
+    }
+
+    /**
+     * Adds a new namespace and its prefix to the list of used namespaces for this
+     * JSON-LD instance.
+     *
+     * @param namespace A namespace IRI.
+     * @param prefix A prefix to use and identify this namespace in serialized JSON-LD.
+     */
+    public void addNamespacePrefix(String namespace, String prefix) {
         namespacePrefixMap.put(namespace, prefix);
-	}
+    }
 
-	/**
-	 * Determine whether currently joint or disjoint graphs are serialized with this JSON-LD instance.
-	 * 
-	 * @return <code>True</code> if joint graphs are used, <code>False</code>otherwise.
-	 */
-	public boolean isUseJointGraphs() {
-		return useJointGraphs;
-	}
-
-	/**
-	 * Set to <code>true</code> if you want to use joint graphs (default) or <code>false</code> otherwise.
-	 * 
-	 * @param useJointGraphs
-	 */
-	public void setUseJointGraphs(boolean useJointGraphs) {
-		this.useJointGraphs = useJointGraphs;
-	}
-
-	/**
-	 * Flag to control whether the namespace prefix map should be used
-	 * to shorten IRIs to prefix notation during serialization. Default
-	 * value is <code>true</code>.
+    /**
+     * Determine whether currently joint or disjoint graphs are serialized with this JSON-LD instance.
+     *
+     * @return <code>True</code> if joint graphs are used, <code>False</code>otherwise.
+     */
+    public boolean isUseJointGraphs() {
+        return useJointGraphs;
+    }
+
+    /**
+     * Set to <code>true</code> if you want to use joint graphs (default) or <code>false</code> otherwise.
+     *
+     * @param useJointGraphs
+     */
+    public void setUseJointGraphs(boolean useJointGraphs) {
+        this.useJointGraphs = useJointGraphs;
+    }
+
+    /**
+     * Flag to control whether the namespace prefix map should be used
+     * to shorten IRIs to prefix notation during serialization. Default
+     * value is <code>true</code>.
      * <p>
-	 * If you already put values into this JSON-LD instance with prefix
-	 * notation, you should set this to <code>false</code> before starting
-	 * the serialization.
-	 *
-	 * @return <code>True</code> if namespaces are applied during serialization, <code>false</code> otherwise.
-	 */
-	public boolean isApplyNamespaces() {
-		return applyNamespaces;
-	}
-
-	/**
-	 * Control whether namespaces from the namespace prefix map are
-	 * applied to URLs during serialization.
+     * If you already put values into this JSON-LD instance with prefix
+     * notation, you should set this to <code>false</code> before starting
+     * the serialization.
+     *
+     * @return <code>True</code> if namespaces are applied during serialization, <code>false</code> otherwise.
+     */
+    public boolean isApplyNamespaces() {
+        return applyNamespaces;
+    }
+
+    /**
+     * Control whether namespaces from the namespace prefix map are
+     * applied to URLs during serialization.
      * <p>
-	 * Set this to <code>false</code> if you already have shortened IRIs
-	 * with prefixes.
-	 * 
-	 * @param applyNamespaces
-	 */
-	public void setApplyNamespaces(boolean applyNamespaces) {
-		this.applyNamespaces = applyNamespaces;
-	}
-	
+     * Set this to <code>false</code> if you already have shortened IRIs
+     * with prefixes.
+     *
+     * @param applyNamespaces
+     */
+    public void setApplyNamespaces(boolean applyNamespaces) {
+        this.applyNamespaces = applyNamespaces;
+    }
+
 }

Modified: incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonLdResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonLdResource.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonLdResource.java (original)
+++ incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonLdResource.java Sun Dec 12 16:10:48 2010
@@ -11,40 +11,40 @@ import java.util.Map;
  */
 public class JsonLdResource {
 
-	private String subject;
-	private List<String> types = new ArrayList<String>();
-	private Map<String, Object> propertyMap = new HashMap<String, Object>();
-
-	public String getSubject() {
-		return subject;
-	}
-
-	public void setSubject(String subject) {
-		this.subject = subject;
-	}
-	
-	public void addType(String type) {
+    private String subject;
+    private List<String> types = new ArrayList<String>();
+    private Map<String, Object> propertyMap = new HashMap<String, Object>();
+
+    public String getSubject() {
+        return subject;
+    }
+
+    public void setSubject(String subject) {
+        this.subject = subject;
+    }
+
+    public void addType(String type) {
         types.add(type);
-	}
+    }
+
+    public void addAllTypes(List<String> types) {
+        this.types.addAll(types);
+    }
 
-	public void addAllTypes(List<String> types) {
-		this.types.addAll(types);
-	}
-	
-	public List<String> getTypes() {
-		return types;
-	}
-	
-	public void putAllProperties(Map<String, Object> propertyMap) {
-		this.propertyMap.putAll(propertyMap);
-	}
-	
-	public void putProperty(String property, Object value) {
+    public List<String> getTypes() {
+        return types;
+    }
+
+    public void putAllProperties(Map<String, Object> propertyMap) {
+        this.propertyMap.putAll(propertyMap);
+    }
+
+    public void putProperty(String property, Object value) {
         propertyMap.put(property, value);
-	}
+    }
+
+    public Map<String, Object> getPropertyMap() {
+        return propertyMap;
+    }
 
-	public Map<String, Object> getPropertyMap() {
-		return propertyMap;
-	}
-	
 }

Modified: incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonSerializer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonSerializer.java?rev=1044841&r1=1044840&r2=1044841&view=diff
==============================================================================
--- incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonSerializer.java (original)
+++ incubator/stanbol/trunk/fise/generic/jsonld/src/main/java/eu/iksproject/fise/jsonld/JsonSerializer.java Sun Dec 12 16:10:48 2010
@@ -7,108 +7,108 @@ import java.util.Map;
 /**
  * Class to serialize a JSON object structure whereby the JSON structure is
  * defined by the basic data types Map and List.
- * 
+ *
  * @author Fabian Christ
  */
 public class JsonSerializer {
 
-	public static String toString(Map<String, Object> jsonMap) {
-		StringBuffer sb = new StringBuffer();
-		
-		appendJsonMap(jsonMap, sb, 0, 0);
-		removeOddChars(sb, 0);
-		
-		return sb.toString();
-	}
-	
-	public static String toString(Map<String, Object> jsonMap, int indent) {
-		StringBuffer sb = new StringBuffer();
-		
-		appendJsonMap(jsonMap, sb, indent, 0);
-		removeOddChars(sb, indent);
-		
-		return sb.toString();
-	}
-	
-	public static String toString(List<Object> jsonArray) {
-		StringBuffer sb = new StringBuffer();
-		
-		appendList(jsonArray, sb, 0, 0);
-		
-		return sb.toString();
-	}
-	
-	public static String toString(List<Object> jsonArray, int indent) {
-		StringBuffer sb = new StringBuffer();
-		
-		appendList(jsonArray, sb, indent, 0);
-		
-		return sb.toString();
-	}	
-	
-	private static void appendJsonMap(Map<String, Object> jsonMap, StringBuffer sb, int indent, int level) {
-		sb.append('{');
-		level = increaseIndentationLevel(sb, indent, level);
-		for (String key : jsonMap.keySet()) {
-			appendIndentation(sb, indent, level);
-			appendQuoted(key, sb);
-			if (indent == 0) {
+    public static String toString(Map<String, Object> jsonMap) {
+        StringBuffer sb = new StringBuffer();
+
+        appendJsonMap(jsonMap, sb, 0, 0);
+        removeOddChars(sb, 0);
+
+        return sb.toString();
+    }
+
+    public static String toString(Map<String, Object> jsonMap, int indent) {
+        StringBuffer sb = new StringBuffer();
+
+        appendJsonMap(jsonMap, sb, indent, 0);
+        removeOddChars(sb, indent);
+
+        return sb.toString();
+    }
+
+    public static String toString(List<Object> jsonArray) {
+        StringBuffer sb = new StringBuffer();
+
+        appendList(jsonArray, sb, 0, 0);
+
+        return sb.toString();
+    }
+
+    public static String toString(List<Object> jsonArray, int indent) {
+        StringBuffer sb = new StringBuffer();
+
+        appendList(jsonArray, sb, indent, 0);
+
+        return sb.toString();
+    }
+
+    private static void appendJsonMap(Map<String, Object> jsonMap, StringBuffer sb, int indent, int level) {
+        sb.append('{');
+        level = increaseIndentationLevel(sb, indent, level);
+        for (String key : jsonMap.keySet()) {
+            appendIndentation(sb, indent, level);
+            appendQuoted(key, sb);
+            if (indent == 0) {
                 sb.append(':');
             } else {
                 sb.append(": ");
             }
-			appendValueOf(jsonMap.get(key), sb, indent, level);
-		}
-		removeOddChars(sb, indent);
-		level = decreaseIndentationLevel(sb, indent, level);
-		appendIndentation(sb, indent, level);
-		sb.append('}').append(',');
-		appendLinefeed(sb, indent);
-	}
+            appendValueOf(jsonMap.get(key), sb, indent, level);
+        }
+        removeOddChars(sb, indent);
+        level = decreaseIndentationLevel(sb, indent, level);
+        appendIndentation(sb, indent, level);
+        sb.append('}').append(',');
+        appendLinefeed(sb, indent);
+    }
 
     @SuppressWarnings("unchecked")
-	private static void appendValueOf(Object object, StringBuffer sb, int indent, int level) {
-    	if (object == null) {
-    		return;
-    	}
-    	
-		if (object instanceof String) {
-			String strValue = (String) object;
-			appendQuoted(strValue, sb);
-			sb.append(',');
-			appendLinefeed(sb, indent);
-		}
-		else if (object instanceof Map<?,?>) {
-			Map<String, Object> mapValue = (Map<String, Object>) object;
-			appendJsonMap(mapValue, sb, indent, level);
-		}
-		else if (object instanceof List<?>) {
-			List<Object> lstValue = (List<Object>) object;
-			appendList(lstValue, sb, indent, level);
-			sb.append(',');
-			appendLinefeed(sb, indent);
-		}
-		else {
-			sb.append(object.toString());
-			sb.append(',');
-		}
-	}
-
-	private static void appendList(List<Object> jsonArray, StringBuffer sb, int indent, int level) {
-		sb.append('[');
-		level = increaseIndentationLevel(sb, indent, level);
-		for (Object object : jsonArray) {
-			appendIndentation(sb, indent, level);
-			appendValueOf(object, sb, indent, level);
-		}
-		removeOddChars(sb, indent);
-		level = decreaseIndentationLevel(sb, indent, level);
-		appendIndentation(sb, indent, level);
-		sb.append(']');
-	}
+    private static void appendValueOf(Object object, StringBuffer sb, int indent, int level) {
+        if (object == null) {
+            return;
+        }
 
-	private static void appendQuoted(String string, StringBuffer sb) {
-		sb.append('"');
+        if (object instanceof String) {
+            String strValue = (String) object;
+            appendQuoted(strValue, sb);
+            sb.append(',');
+            appendLinefeed(sb, indent);
+        }
+        else if (object instanceof Map<?,?>) {
+            Map<String, Object> mapValue = (Map<String, Object>) object;
+            appendJsonMap(mapValue, sb, indent, level);
+        }
+        else if (object instanceof List<?>) {
+            List<Object> lstValue = (List<Object>) object;
+            appendList(lstValue, sb, indent, level);
+            sb.append(',');
+            appendLinefeed(sb, indent);
+        }
+        else {
+            sb.append(object.toString());
+            sb.append(',');
+        }
+    }
+
+    private static void appendList(List<Object> jsonArray, StringBuffer sb, int indent, int level) {
+        sb.append('[');
+        level = increaseIndentationLevel(sb, indent, level);
+        for (Object object : jsonArray) {
+            appendIndentation(sb, indent, level);
+            appendValueOf(object, sb, indent, level);
+        }
+        removeOddChars(sb, indent);
+        level = decreaseIndentationLevel(sb, indent, level);
+        appendIndentation(sb, indent, level);
+        sb.append(']');
+    }
+
+    private static void appendQuoted(String string, StringBuffer sb) {
+        sb.append('"');
         for (int i = 0; i < string.length(); i++) {
             char ch = string.charAt(i);
             switch (ch) {
@@ -148,38 +148,38 @@ public class JsonSerializer {
         sb.append('"');
     }
 
-	private static void appendIndentation(StringBuffer sb, int indent, int level) {
-		for (int i=0; i<(indent*level); i++) {
-        	sb.append(' ');
-        }
-	}
-	
-	private static int decreaseIndentationLevel(StringBuffer sb, int indent, int level) {
-		if (indent > 0) {
-			appendLinefeed(sb, indent);
-			level--;
-		}
-		return level;
-	}
-
-	private static int increaseIndentationLevel(StringBuffer sb, int indent, int level) {
-		if (indent > 0) {
-			appendLinefeed(sb, indent);
-			level++;
-		}
-		return level;
-	}
-	
-	private static void appendLinefeed(StringBuffer sb, int indent) {
-		if (indent > 0) {
-			sb.append('\n');
-		}
-	}
-	
-	private static void removeOddChars(StringBuffer sb, int indent) {
-		sb.deleteCharAt(sb.length()-1);
-		if (indent > 0) {
-			sb.deleteCharAt(sb.length()-1);
-		}
-	}
+    private static void appendIndentation(StringBuffer sb, int indent, int level) {
+        for (int i=0; i<(indent*level); i++) {
+            sb.append(' ');
+        }
+    }
+
+    private static int decreaseIndentationLevel(StringBuffer sb, int indent, int level) {
+        if (indent > 0) {
+            appendLinefeed(sb, indent);
+            level--;
+        }
+        return level;
+    }
+
+    private static int increaseIndentationLevel(StringBuffer sb, int indent, int level) {
+        if (indent > 0) {
+            appendLinefeed(sb, indent);
+            level++;
+        }
+        return level;
+    }
+
+    private static void appendLinefeed(StringBuffer sb, int indent) {
+        if (indent > 0) {
+            sb.append('\n');
+        }
+    }
+
+    private static void removeOddChars(StringBuffer sb, int indent) {
+        sb.deleteCharAt(sb.length()-1);
+        if (indent > 0) {
+            sb.deleteCharAt(sb.length()-1);
+        }
+    }
 }