/* Functions defined in this file for use as RDFMapper parameters: ________________ geom2d:Point function extractLocation(Resource itm) Looks for geo coordinates of itm in the following order (1) a geom2d:Point as the value of dc:coverage (2) geo:lat, geo:long properties (3) scrapes content:encoded,dc:description,rss:description values for , ________________ geom2d:Point function extractTopicLocation(Resource itm) Extracts geo:lat,geo:long from itm.foaf:topic ________________ string function itemTitleGen0(Resource itm) looks for dc:title, rss:title ________________ string function channelTitle(Resource x) looks for dc:title, rss:title, restricted to values of type rss:channel ________________ string function pageGen0(string title,inHead,inBody) A simple page generator; only the basics (see code for details) ________________ void function itemGen0(string rs,Resource x) An item generator suitable for RSS: emits title and description _________________ void function itemGen1(string rs,Resource x) An item generator suitable for GeoURL: emits links to the resource that itm is about _________________ */ install(namespace('geom2d')); install(namespace('dc')); install(namespace('rss')); install(namespace('geo')); install(namespace('libgeom2d')); install(namespace('content')); setHomeAndTopic(resource("http://www.mapbureau.com/lib/rdfmapper_utils-2.0")); // needed for compilation startCollectingTriples(); push(path,namespace('libgeom2d')); startCollectingTriples(); boolean function hasTypeChannel(Resource x) { return hasType(x,rss:channel); } boolean function hasTypeItem(Resource x) { return hasType(x,rss:item); } string function extractTag(string s,tag) { var string tg,int ln,idx,eidx; tg = "<"; tg * tag; tg * ">"; ln = length(tg); idx = indexOf(s,tg); if (idx >= 0) { reset(tg); tg * ""; eidx = indexOf(s,tg,idx); if (eidx >= 0) return slice(s,idx+ln,eidx); } return nil~string; } geom2d:Point function scrapePoint(string s) { var string lt,ln,double ltd,lnd,geom2d:Point rs; lt = extractTag(s,"geo:lat"); if (nul(lt)) return nil ~ geom2d:Point; ln = extractTag(s,"geo:long"); if (nul(ln)) return nil ~ geom2d:Point; ltd = toDouble(lt); lnd = toDouble(ln); rs = new(geom2d:Point); rs . geom2d:x = lnd; rs . geom2d:y = ltd; return rs; } geom2d:Point function extractGeoLatLong(Resource x) { var geom2d:Point rs; if ((count(x,geo:lat)>0) && (count(x,geo:long)>0)) { rs = new(geom2d:Point); rs . geom2d:x = x.geo:long; rs . geom2d:y = x.geo:lat; return rs; } return nil ~ geom2d:Point; } geom2d:Point function extractLocation(Resource itm) { var Resource dcc,geom2d:Point rs,string cne; dcc = itm.dc:coverage; if (hasType(dcc,geom2d:Point)) return dcc ~ geom2d:Point; rs = extractGeoLatLong(itm); if (nnul(rs)) return rs; if (count(itm,content:encoded) > 0) { cne = itm.content:encoded ~ string; rs = scrapePoint(cne); if (nnul(rs)) return rs; } if (count(itm,dc:description) > 0) { cne = itm.dc:description ~ string; rs = scrapePoint(cne); if (nnul(rs)) return rs; } if (count(itm,rss:description) > 0) { cne = itm.rss:description ~ string; rs = scrapePoint(cne); if (nnul(rs)) return rs; } return nil~geom2d:Point; } geom2d:Point function extractTopicLocation(Resource itm) { var Resource dcc,geom2d:Point rs,string cne; if (count(itm,foaf:topic)>0) return extractGeoLatLong(itm.foaf:topic); return nil ~ geom2d:Point; } string function itemTitleGen0(Resource itm) { var string rs; rs = itm . dc:title~string; if (nul(rs)) rs = itm . rss:title ~string; if (nul(rs)) rs = "Untitled"; return rs; } string function channelTitle(Resource itm) { var string rs; if (!hasType(itm,rss:channel)) return nil~string; rs = itm . dc:title~string; if (nul(rs)) rs = itm . rss:title ~string; return rs; } // very simple string function pageGen0(string title,inHead,map) { var string ttl,stl; return " {inHead} RDFMapper {map}
{title}
"; } void function itemGen0(string rs,Resource x) { var string dc,lnk,ttl,imgu,Resource img; dc = x . content:encoded ~ string; if (nul(dc)) dc = x . dc:description ~ string; if (nul(dc)) dc = x . rss:description ~ string; ttl = x . dc:title ~ string; if (nul(ttl)) ttl = x . rss:title~string; lnk = x . rss:link ~ string; if (nnul(ttl)) writeTo(rs,"

{ttl}

"); if (nnul(dc)) writeTo(rs,"

{dc}

"); if (nnul(lnk)) { writeTo(rs,"

Link

"); } } void function itemGen1(string rs,Resource x) { var string dc,lnk,ttl,imgu,Resource img; dc = x . content:encoded ~ string; if (nul(dc)) dc = x . dc:description ~ string; if (nul(dc)) dc = x . rss:description ~ string; ttl = x . dc:title ~ string; if (nul(ttl)) ttl = x . rss:title~string; if (nul(ttl)) ttl = "Untitled"; lnk = uri(x); if (nul(lnk)) writeTo(rs,"

{ttl}

"); else writeTo(rs,"

{ttl}

"); if (nnul(dc)) writeTo(rs,"

Description

{ttl}

"); } /* compile("file://../lib/rdfmapper_utils-2.0.fb","file://../libsrc/rdfmapper_utils-2.0-6.fbl"); */