<> a <http://www.w3.org/2000/10/swap/log#N3Document>.

@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix str: <http://www.w3.org/2000/10/swap/string#>.
@prefix : <teamToGlobe#>.

@forAll :txt, :txt2, :pg2, :cname, :fname, :pname,
  :where, :city, :pat, :who, :lat, :lon.

@prefix c: <http://www.w3.org/2000/10/swap/pim/contact#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/>.

@prefix map: <http://www.w3.org/2000/10/swap/pim/earthMap#>.

:w3t c:mailbox <mailto:w3t@w3.org>;
  :hasMembersIn
    [ :countryName "France" ],
    [ :countryName "United States" ],
    [ :countryName "Japan" ],
    [ :countryName "Netherlands" ],
    [ :countryName "Australia" ],
    [ :countryName "Canada" ]
  .

{ [ c:mailbox <mailto:w3t@w3.org> ] :hasMembersIn :where.
  :where :countryName :cname.

  <http://www.un.org/Depts/unsd/demog/ctry.htm> log:content :txt.

  ( "<A HREF=\"([^\"]+)\">" :cname "<" ) str:concatenation :pat.

  (:txt :pat ) str:scrape :fname.

  ( "http://www.un.org/Depts/unsd/demog/" :fname ) str:concatenation [ is log:uri of :pg2].
}
  log:implies { :where :UNcitiesPage :pg2 }.

:Nice :cityName "Nice";
  :suburb [ :cityName "Sophia", "Sophia Antipolis" ].
:Boston :cityName "Boston";
  :suburb [ :cityName "Cambridge"].
:KC :cityName "KC", "Kansas City".

{ :who foaf:site [ is :cityName of :where ]. }
  log:implies { :who :worksNear :where }.

{ :who foaf:site :cname. }
  log:implies { :who :worksNear [ :cityName :cname] }.

{ :who :worksNear [ is :suburb of :where ] }
 log:implies { :who :worksNear :where }.


{ :who foaf:name :pname; :worksNear [ :cityName :cname].
  [ :UNcitiesPage :pg2 ].
  :pg2 log:content :txt.

  :txt str:contains :cname.

  ( "(<TD.*>" :cname "( \\(|<).*/TR>)" ) str:concatenation :pat. # @@very fragile!

  (:txt :pat) str:scrape :txt2.

  # <TD WIDTH=120  ALIGN=RIGHT ><FONT SIZE=1 FACE="Times New Roman" COLOR=#000000>32.83</FONT></TD><TD WIDTH=85  ALIGN=RIGHT ><FONT SIZE=1 FACE="Times New Roman" COLOR=#000000>-117.17</FONT></TD></TR>

  (:txt2      "<TD.*<TD.*<TD.*<TD.*<TD.*<TD[^>]+><FONT[^>]+>(-?\\d+.\\d+)<.*<TD") str:scrape :lat.
  (:txt2 "<TD.*<TD.*<TD.*<TD.*<TD.*<TD.*<TD[^>]+><FONT[^>]+>(-?\\d+.\\d+)<") str:scrape :lon.

}
  log:implies { [ a map:Marker; map:y :lat; map:x :lon; :_name :pname; :_pg :pg2; :_cityName :cname; ] }.
