mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-22 17:42:51 -06:00
fixes in partitives in Phrasebook
This commit is contained in:
@@ -85,6 +85,7 @@ gfdoc - a rudimentary GF document generator.
|
|||||||
ObjItem i = i ;
|
ObjItem i = i ;
|
||||||
ObjNumber n k = mkNP n k ;
|
ObjNumber n k = mkNP n k ;
|
||||||
ObjIndef k = mkNP a_Quant k ;
|
ObjIndef k = mkNP a_Quant k ;
|
||||||
|
ObjPlural k = mkNP aPl_Det k ;
|
||||||
ObjMass k = mkNP k ;
|
ObjMass k = mkNP k ;
|
||||||
ObjAndObj = mkNP and_Conj ;
|
ObjAndObj = mkNP and_Conj ;
|
||||||
OneObj o = o ;
|
OneObj o = o ;
|
||||||
@@ -129,8 +130,7 @@ gfdoc - a rudimentary GF document generator.
|
|||||||
|
|
||||||
NNumeral n = mkCard <lin Numeral n : Numeral> ;
|
NNumeral n = mkCard <lin Numeral n : Numeral> ;
|
||||||
|
|
||||||
AHave p kind = mkCl p.name have_V2 (mkNP aPl_Det kind) ;
|
AHave p obj = mkCl p.name have_V2 obj ;
|
||||||
AHaveMass p kind = mkCl p.name have_V2 (mkNP kind) ;
|
|
||||||
AHaveCurr p curr = mkCl p.name have_V2 (mkNP aPl_Det curr) ;
|
AHaveCurr p curr = mkCl p.name have_V2 (mkNP aPl_Det curr) ;
|
||||||
ACitizen p n = mkCl p.name n ;
|
ACitizen p n = mkCl p.name n ;
|
||||||
ABePlace p place = mkCl p.name place.at ;
|
ABePlace p place = mkCl p.name place.at ;
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ all: fin demo missing
|
|||||||
demo: compdemo linkdemo
|
demo: compdemo linkdemo
|
||||||
|
|
||||||
compdemo:
|
compdemo:
|
||||||
$(compile) Bul Dan Dut Eng Fre Ger Ita Nor Ron Spa Swe DisambPhrasebookEng
|
$(compile) Bul Cat Dan Dut Eng Fre Ger Ita Nor Ron Spa Swe DisambPhrasebookEng
|
||||||
|
|
||||||
linkdemo:
|
linkdemo:
|
||||||
$(compile) -link Eng Bul Dan Dut Fin Fre Ger Ita Nor Ron Spa Swe DisambPhrasebookEng
|
$(compile) -link Eng Bul Cat Dan Dut Fin Fre Ger Ita Nor Ron Spa Swe DisambPhrasebookEng
|
||||||
|
|
||||||
#separate, because slow...
|
#separate, because slow...
|
||||||
fin:
|
fin:
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ Here are some general syntactic constructions.
|
|||||||
ObjItem : Item -> PrimObject ; -- this pizza
|
ObjItem : Item -> PrimObject ; -- this pizza
|
||||||
ObjNumber : Number -> Kind -> PrimObject ; -- five pizzas
|
ObjNumber : Number -> Kind -> PrimObject ; -- five pizzas
|
||||||
ObjIndef : Kind -> PrimObject ; -- a pizza
|
ObjIndef : Kind -> PrimObject ; -- a pizza
|
||||||
|
ObjPlural : Kind -> PrimObject ; -- pizzas
|
||||||
ObjMass : MassKind -> PrimObject ; -- water
|
ObjMass : MassKind -> PrimObject ; -- water
|
||||||
ObjAndObj : PrimObject -> Object -> Object ; -- this pizza and a beer
|
ObjAndObj : PrimObject -> Object -> Object ; -- this pizza and a beer
|
||||||
OneObj : PrimObject -> Object ; -- this pizza
|
OneObj : PrimObject -> Object ; -- this pizza
|
||||||
@@ -146,8 +147,7 @@ Determiners.
|
|||||||
Actions are typically language-dependent, not only lexically but also
|
Actions are typically language-dependent, not only lexically but also
|
||||||
structurally. However, these ones are mostly functorial.
|
structurally. However, these ones are mostly functorial.
|
||||||
<pre>
|
<pre>
|
||||||
AHave : Person -> Kind -> Action ; -- you have pizzas
|
AHave : Person -> Object -> Action ; -- you have pizzas
|
||||||
AHaveMass : Person -> MassKind -> Action ; -- you have water
|
|
||||||
AHaveCurr : Person -> Currency -> Action ; -- you have dollars
|
AHaveCurr : Person -> Currency -> Action ; -- you have dollars
|
||||||
ACitizen : Person -> Citizenship -> Action ; -- you are Swedish
|
ACitizen : Person -> Citizenship -> Action ; -- you are Swedish
|
||||||
ABePlace : Person -> Place -> Action ; -- you are in the bar
|
ABePlace : Person -> Place -> Action ; -- you are in the bar
|
||||||
@@ -300,7 +300,7 @@ Notice that also negations and questions can be formed from these.
|
|||||||
AThirsty : Person -> Action ; -- I am thirsty
|
AThirsty : Person -> Action ; -- I am thirsty
|
||||||
ATired : Person -> Action ; -- I am tired
|
ATired : Person -> Action ; -- I am tired
|
||||||
AUnderstand : Person -> Action ; -- I (don't) understand
|
AUnderstand : Person -> Action ; -- I (don't) understand
|
||||||
AWant : Person -> Object -> Action ; -- I want two beers
|
AWant : Person -> Object -> Action ; -- I want two apples
|
||||||
AWantGo : Person -> Place -> Action ; -- I want to go to the hospital
|
AWantGo : Person -> Place -> Action ; -- I want to go to the hospital
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ abstract Sentences = Numeral ** {
|
|||||||
ObjItem : Item -> PrimObject ; -- this pizza
|
ObjItem : Item -> PrimObject ; -- this pizza
|
||||||
ObjNumber : Number -> Kind -> PrimObject ; -- five pizzas
|
ObjNumber : Number -> Kind -> PrimObject ; -- five pizzas
|
||||||
ObjIndef : Kind -> PrimObject ; -- a pizza
|
ObjIndef : Kind -> PrimObject ; -- a pizza
|
||||||
|
ObjPlural : Kind -> PrimObject ; -- pizzas
|
||||||
ObjMass : MassKind -> PrimObject ; -- water
|
ObjMass : MassKind -> PrimObject ; -- water
|
||||||
ObjAndObj : PrimObject -> Object -> Object ; -- this pizza and a beer
|
ObjAndObj : PrimObject -> Object -> Object ; -- this pizza and a beer
|
||||||
OneObj : PrimObject -> Object ; -- this pizza
|
OneObj : PrimObject -> Object ; -- this pizza
|
||||||
@@ -133,8 +134,7 @@ abstract Sentences = Numeral ** {
|
|||||||
-- Actions are typically language-dependent, not only lexically but also
|
-- Actions are typically language-dependent, not only lexically but also
|
||||||
-- structurally. However, these ones are mostly functorial.
|
-- structurally. However, these ones are mostly functorial.
|
||||||
|
|
||||||
AHave : Person -> Kind -> Action ; -- you have pizzas
|
AHave : Person -> Object -> Action ; -- you have pizzas
|
||||||
AHaveMass : Person -> MassKind -> Action ; -- you have water
|
|
||||||
AHaveCurr : Person -> Currency -> Action ; -- you have dollars
|
AHaveCurr : Person -> Currency -> Action ; -- you have dollars
|
||||||
ACitizen : Person -> Citizenship -> Action ; -- you are Swedish
|
ACitizen : Person -> Citizenship -> Action ; -- you are Swedish
|
||||||
ABePlace : Person -> Place -> Action ; -- you are in the bar
|
ABePlace : Person -> Place -> Action ; -- you are in the bar
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
concrete SentencesFin of Sentences = NumeralFin ** SentencesI -
|
concrete SentencesFin of Sentences = NumeralFin ** SentencesI -
|
||||||
[Is,NameNN,
|
[Is, NameNN, ObjMass,
|
||||||
IFemale, YouFamFemale, YouPolFemale, IMale, YouFamMale, YouPolMale
|
IFemale, YouFamFemale, YouPolFemale, IMale, YouFamMale, YouPolMale
|
||||||
] with
|
] with
|
||||||
(Syntax = SyntaxFin),
|
(Syntax = SyntaxFin),
|
||||||
@@ -15,5 +15,8 @@ concrete SentencesFin of Sentences = NumeralFin ** SentencesI -
|
|||||||
YouFamMale, YouFamFemale =
|
YouFamMale, YouFamFemale =
|
||||||
{name = mkNP (ProDrop youSg_Pron) ; isPron = True ; poss = mkQuant youSg_Pron} ;
|
{name = mkNP (ProDrop youSg_Pron) ; isPron = True ; poss = mkQuant youSg_Pron} ;
|
||||||
YouPolMale, YouPolFemale =
|
YouPolMale, YouPolFemale =
|
||||||
{name = mkNP (ProDrop youPol_Pron) ; isPron = True ; poss = mkQuant youPol_Pron};
|
{name = mkNP (ProDrop youPol_Pron) ; isPron = True ; poss = mkQuant youPol_Pron} ;
|
||||||
|
|
||||||
|
ObjMass = PartCN ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ incomplete concrete SentencesI of Sentences = Numeral **
|
|||||||
ObjItem i = i ;
|
ObjItem i = i ;
|
||||||
ObjNumber n k = mkNP n k ;
|
ObjNumber n k = mkNP n k ;
|
||||||
ObjIndef k = mkNP a_Quant k ;
|
ObjIndef k = mkNP a_Quant k ;
|
||||||
|
ObjPlural k = mkNP aPl_Det k ;
|
||||||
ObjMass k = mkNP k ;
|
ObjMass k = mkNP k ;
|
||||||
ObjAndObj = mkNP and_Conj ;
|
ObjAndObj = mkNP and_Conj ;
|
||||||
OneObj o = o ;
|
OneObj o = o ;
|
||||||
@@ -120,8 +121,7 @@ incomplete concrete SentencesI of Sentences = Numeral **
|
|||||||
|
|
||||||
NNumeral n = mkCard <lin Numeral n : Numeral> ;
|
NNumeral n = mkCard <lin Numeral n : Numeral> ;
|
||||||
|
|
||||||
AHave p kind = mkCl p.name have_V2 (mkNP aPl_Det kind) ;
|
AHave p obj = mkCl p.name have_V2 obj ;
|
||||||
AHaveMass p kind = mkCl p.name have_V2 (mkNP kind) ;
|
|
||||||
AHaveCurr p curr = mkCl p.name have_V2 (mkNP aPl_Det curr) ;
|
AHaveCurr p curr = mkCl p.name have_V2 (mkNP aPl_Det curr) ;
|
||||||
ACitizen p n = mkCl p.name n ;
|
ACitizen p n = mkCl p.name n ;
|
||||||
ABePlace p place = mkCl p.name place.at ;
|
ABePlace p place = mkCl p.name place.at ;
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ abstract Words = Sentences ** {
|
|||||||
AThirsty : Person -> Action ; -- I am thirsty
|
AThirsty : Person -> Action ; -- I am thirsty
|
||||||
ATired : Person -> Action ; -- I am tired
|
ATired : Person -> Action ; -- I am tired
|
||||||
AUnderstand : Person -> Action ; -- I (don't) understand
|
AUnderstand : Person -> Action ; -- I (don't) understand
|
||||||
AWant : Person -> Object -> Action ; -- I want two beers
|
AWant : Person -> Object -> Action ; -- I want two apples
|
||||||
AWantGo : Person -> Place -> Action ; -- I want to go to the hospital
|
AWantGo : Person -> Place -> Action ; -- I want to go to the hospital
|
||||||
|
|
||||||
-- Miscellaneous phrases. Notice that also negations and questions can be formed from
|
-- Miscellaneous phrases. Notice that also negations and questions can be formed from
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-- (c) 2009 Aarne Ranta under LGPL
|
-- (c) 2010 Aarne Ranta under LGPL
|
||||||
|
|
||||||
concrete WordsFin of Words = SentencesFin **
|
concrete WordsFin of Words = SentencesFin **
|
||||||
open
|
open
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
DisambPhrasebookEng :
|
DisambPhrasebookEng :
|
||||||
PhrasebookBul : GCongratulations GGoodLuck GHappyBirthday
|
PhrasebookBul : GCongratulations GGoodLuck GHappyBirthday
|
||||||
|
PhrasebookCat : pot01
|
||||||
PhrasebookDan :
|
PhrasebookDan :
|
||||||
PhrasebookDut :
|
PhrasebookDut :
|
||||||
PhrasebookEng :
|
PhrasebookEng :
|
||||||
PhrasebookFin :
|
PhrasebookFin :
|
||||||
PhrasebookFre :
|
PhrasebookFre :
|
||||||
PhrasebookGer :
|
PhrasebookGer :
|
||||||
PhrasebookIta : HowFar HowFarBy HowFarFrom HowFarFromBy Pound
|
PhrasebookIta :
|
||||||
PhrasebookNor :
|
PhrasebookNor :
|
||||||
PhrasebookRon :
|
PhrasebookRon :
|
||||||
PhrasebookSpa : GCongratulations GGoodLuck GHappyBirthday
|
PhrasebookSpa : GCongratulations GGoodLuck GHappyBirthday
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
</HEAD><BODY BGCOLOR="white" TEXT="black">
|
</HEAD><BODY BGCOLOR="white" TEXT="black">
|
||||||
<P ALIGN="center"><CENTER><H1>MOLTO Multilingual Phrasebook</H1>
|
<P ALIGN="center"><CENTER><H1>MOLTO Multilingual Phrasebook</H1>
|
||||||
<FONT SIZE="4">
|
<FONT SIZE="4">
|
||||||
<I>Krasimir Angelov, Olga Caprotti, Ramona Enache, Thomas Hallgren, Inari Listenmaa, Aarne Ranta </I><BR>
|
<I>Krasimir Angelov, Olga Caprotti, Ramona Enache, Thomas Hallgren, Inari Listenmaa, Aarne Ranta, Jordi Saludes </I><BR>
|
||||||
|
Showcase for project FP7-ICT-247914, Deliverable D10.2.
|
||||||
</FONT></CENTER>
|
</FONT></CENTER>
|
||||||
|
|
||||||
<P>
|
<P>
|
||||||
@@ -17,9 +18,11 @@
|
|||||||
History
|
History
|
||||||
</P>
|
</P>
|
||||||
<UL>
|
<UL>
|
||||||
<LI>20 May. Version 0.9:
|
<LI>26 May. Version 0.9:
|
||||||
|
Catalan added, mass/count noun distinction to reduce overgeneration,
|
||||||
|
improved web interface.
|
||||||
|
<LI>20 May. Version 0.8:
|
||||||
Spanish added, Bulgarian complete.
|
Spanish added, Bulgarian complete.
|
||||||
<P></P>
|
|
||||||
<LI>9 May. Version 0.7:
|
<LI>9 May. Version 0.7:
|
||||||
Danish and Norwegian added (preliminary versions induced from statistical models
|
Danish and Norwegian added (preliminary versions induced from statistical models
|
||||||
and resource grammars).
|
and resource grammars).
|
||||||
@@ -39,7 +42,7 @@ History
|
|||||||
<A HREF="missing.txt">Missing constructs</A>
|
<A HREF="missing.txt">Missing constructs</A>
|
||||||
</P>
|
</P>
|
||||||
<P>
|
<P>
|
||||||
<A HREF="http://tournesol.cs.chalmers.se/~aarne/phrasebook/phrasebook.html">Back to phrasebook</A>
|
<A HREF="http://www.grammaticalframework.org/demos/phrasebook/">Back to phrasebook</A>
|
||||||
</P>
|
</P>
|
||||||
<P>
|
<P>
|
||||||
</font>
|
</font>
|
||||||
@@ -81,18 +84,17 @@ The source code resides in
|
|||||||
<A HREF="http://code.haskell.org/gf/examples/phrasebook/"><CODE>code.haskell.org/gf/examples/phrasebook/</CODE></A>
|
<A HREF="http://code.haskell.org/gf/examples/phrasebook/"><CODE>code.haskell.org/gf/examples/phrasebook/</CODE></A>
|
||||||
</P>
|
</P>
|
||||||
<P>
|
<P>
|
||||||
Current status (20 May 2010):
|
Current status (26 May 2010):
|
||||||
</P>
|
</P>
|
||||||
<UL>
|
<UL>
|
||||||
<LI>small but useful coverage in abstract syntax
|
<LI>small but useful coverage in abstract syntax
|
||||||
<LI>reasonable implementations for
|
<LI>reasonable implementations for
|
||||||
Bulgarian, Danish, Dutch, English, Finnish, French, German,
|
Bulgarian, Catalan, Danish, Dutch, English, Finnish, French, German,
|
||||||
Italian, Norwegian, Romanian, Spanish, Swedish
|
Italian, Norwegian, Romanian, Spanish, Swedish
|
||||||
<LI>mostly just cloned for the rest of MOLTO languages
|
<LI>Polish and Russian under construction
|
||||||
<LI>temporary user interdace
|
|
||||||
<LI>works on web browsers calling a server
|
<LI>works on web browsers calling a server
|
||||||
<LI>web service not yet released, but preliminarily available in
|
<LI>web service not yet released, but preliminarily available in
|
||||||
<A HREF="http://tournesol.cs.chalmers.se/~aarne/phrasebook/phrasebook.html"><CODE>http://tournesol.cs.chalmers.se/~aarne/phrasebook/phrasebook.html</CODE></A>
|
<A HREF="http://www.grammaticalframework.org/demos/phrasebook/">http://www.grammaticalframework.org/demos/phrasebook/</A>
|
||||||
</UL>
|
</UL>
|
||||||
|
|
||||||
<H1>Points illustrated</H1>
|
<H1>Points illustrated</H1>
|
||||||
@@ -150,6 +152,9 @@ Separate concrete syntaxes.
|
|||||||
the input language is ambiguous.
|
the input language is ambiguous.
|
||||||
</P>
|
</P>
|
||||||
<P>
|
<P>
|
||||||
|
<CODE>Numeral</CODE>: resource grammar module directly inherited from the library.
|
||||||
|
</P>
|
||||||
|
<P>
|
||||||
Here is the module structure as produced in GF by
|
Here is the module structure as produced in GF by
|
||||||
</P>
|
</P>
|
||||||
<PRE>
|
<PRE>
|
||||||
@@ -252,6 +257,6 @@ Here are the steps to follow for contributors:
|
|||||||
</UL>
|
</UL>
|
||||||
|
|
||||||
|
|
||||||
<!-- html code generated by txt2tags 2.4 (http://txt2tags.sf.net) -->
|
<!-- html code generated by txt2tags 2.5 (http://txt2tags.sf.net) -->
|
||||||
<!-- cmdline: txt2tags -thtml phrasebook.txt -->
|
<!-- cmdline: txt2tags -thtml phrasebook.txt -->
|
||||||
</BODY></HTML>
|
</BODY></HTML>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
MOLTO Multilingual Phrasebook
|
MOLTO Multilingual Phrasebook
|
||||||
Krasimir Angelov, Olga Caprotti, Ramona Enache, Thomas Hallgren, Inari Listenmaa, Aarne Ranta
|
Krasimir Angelov, Olga Caprotti, Ramona Enache, Thomas Hallgren, Inari Listenmaa, Aarne Ranta, Jordi Saludes
|
||||||
|
Showcase for project FP7-ICT-247914, Deliverable D10.2.
|
||||||
|
|
||||||
|
|
||||||
%!postproc(html): #HR <HR>
|
%!postproc(html): #HR <HR>
|
||||||
@@ -13,9 +14,11 @@ Krasimir Angelov, Olga Caprotti, Ramona Enache, Thomas Hallgren, Inari Listenmaa
|
|||||||
#BSMALL
|
#BSMALL
|
||||||
|
|
||||||
History
|
History
|
||||||
- 20 May. Version 0.9:
|
- 26 May. Version 0.9:
|
||||||
|
Catalan added, mass/count noun distinction to reduce overgeneration,
|
||||||
|
improved web interface.
|
||||||
|
- 20 May. Version 0.8:
|
||||||
Spanish added, Bulgarian complete.
|
Spanish added, Bulgarian complete.
|
||||||
|
|
||||||
- 9 May. Version 0.7:
|
- 9 May. Version 0.7:
|
||||||
Danish and Norwegian added (preliminary versions induced from statistical models
|
Danish and Norwegian added (preliminary versions induced from statistical models
|
||||||
and resource grammars).
|
and resource grammars).
|
||||||
@@ -33,7 +36,7 @@ History
|
|||||||
|
|
||||||
[Missing constructs missing.txt]
|
[Missing constructs missing.txt]
|
||||||
|
|
||||||
[Back to phrasebook http://tournesol.cs.chalmers.se/~aarne/phrasebook/phrasebook.html]
|
[Back to phrasebook http://www.grammaticalframework.org/demos/phrasebook/]
|
||||||
|
|
||||||
#ESMALL
|
#ESMALL
|
||||||
#HR
|
#HR
|
||||||
@@ -68,16 +71,15 @@ The source code resides in
|
|||||||
[``code.haskell.org/gf/examples/phrasebook/`` http://code.haskell.org/gf/examples/phrasebook/]
|
[``code.haskell.org/gf/examples/phrasebook/`` http://code.haskell.org/gf/examples/phrasebook/]
|
||||||
|
|
||||||
|
|
||||||
Current status (20 May 2010):
|
Current status (26 May 2010):
|
||||||
- small but useful coverage in abstract syntax
|
- small but useful coverage in abstract syntax
|
||||||
- reasonable implementations for
|
- reasonable implementations for
|
||||||
Bulgarian, Danish, Dutch, English, Finnish, French, German,
|
Bulgarian, Catalan, Danish, Dutch, English, Finnish, French, German,
|
||||||
Italian, Norwegian, Romanian, Spanish, Swedish
|
Italian, Norwegian, Romanian, Spanish, Swedish
|
||||||
- mostly just cloned for the rest of MOLTO languages
|
- Polish and Russian under construction
|
||||||
- temporary user interdace
|
|
||||||
- works on web browsers calling a server
|
- works on web browsers calling a server
|
||||||
- web service not yet released, but preliminarily available in
|
- web service not yet released, but preliminarily available in
|
||||||
[``http://tournesol.cs.chalmers.se/~aarne/phrasebook/phrasebook.html`` http://tournesol.cs.chalmers.se/~aarne/phrasebook/phrasebook.html]
|
http://www.grammaticalframework.org/demos/phrasebook/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -131,6 +133,8 @@ Separate concrete syntaxes.
|
|||||||
``DisambPhrasebook``: disambiguation grammars generating feedback phrases if
|
``DisambPhrasebook``: disambiguation grammars generating feedback phrases if
|
||||||
the input language is ambiguous.
|
the input language is ambiguous.
|
||||||
|
|
||||||
|
``Numeral``: resource grammar module directly inherited from the library.
|
||||||
|
|
||||||
Here is the module structure as produced in GF by
|
Here is the module structure as produced in GF by
|
||||||
```
|
```
|
||||||
> i -retain DisambPhrasebookEng.gf
|
> i -retain DisambPhrasebookEng.gf
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
/* --- Accessing document elements ------------------------------------------ */
|
||||||
|
|
||||||
function element(id) {
|
function element(id) {
|
||||||
return document.getElementById(id);
|
return document.getElementById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- JSONP ---------------------------------------------------------------- */
|
||||||
|
|
||||||
// Inspired by the function jsonp from
|
// Inspired by the function jsonp from
|
||||||
// http://www.west-wind.com/Weblog/posts/107136.aspx
|
// http://www.west-wind.com/Weblog/posts/107136.aspx
|
||||||
// See also http://niryariv.wordpress.com/2009/05/05/jsonp-quickly/
|
// See also http://niryariv.wordpress.com/2009/05/05/jsonp-quickly/
|
||||||
@@ -12,8 +16,8 @@ function jsonp(url,callback)
|
|||||||
url += "&jsonp="
|
url += "&jsonp="
|
||||||
else
|
else
|
||||||
url += "?jsonp="
|
url += "?jsonp="
|
||||||
url += callback + "&";
|
url += callback;
|
||||||
//url += new Date().getTime().toString(); // prevent caching
|
//url += "&" + new Date().getTime().toString(); // prevent caching
|
||||||
|
|
||||||
var script = empty("script");
|
var script = empty("script");
|
||||||
script.setAttribute("src",url);
|
script.setAttribute("src",url);
|
||||||
@@ -52,6 +56,7 @@ function div_class(cls,contents) { return wrap_class("div",cls,contents); }
|
|||||||
|
|
||||||
function p(contents) { return wrap("p",contents); }
|
function p(contents) { return wrap("p",contents); }
|
||||||
function dt(contents) { return wrap("dt",contents); }
|
function dt(contents) { return wrap("dt",contents); }
|
||||||
|
function li(contents) { return wrap("li",contents); }
|
||||||
|
|
||||||
function th(contents) { return wrap("th",contents); }
|
function th(contents) { return wrap("th",contents); }
|
||||||
function td(contents) { return wrap("td",contents); }
|
function td(contents) { return wrap("td",contents); }
|
||||||
@@ -64,13 +69,18 @@ function tr(cells) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function button(label,action) {
|
function button(label,action) {
|
||||||
var el=empty("input");
|
var el=empty("input","type","button");
|
||||||
el.setAttribute("type","button");
|
|
||||||
el.setAttribute("value",label);
|
el.setAttribute("value",label);
|
||||||
el.setAttribute("onclick",action);
|
el.setAttribute("onclick",action);
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function option(label,value) {
|
||||||
|
var el=empty("option","value",value);
|
||||||
|
el.innerHTML=label;
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
function appendChildren(el,cs) {
|
function appendChildren(el,cs) {
|
||||||
for(var i=0;i<cs.length;i++)
|
for(var i=0;i<cs.length;i++)
|
||||||
el.appendChild(cs[i]);
|
el.appendChild(cs[i]);
|
||||||
@@ -107,7 +117,10 @@ function swap(a,i,j) { // Note: this doesn't work on strings.
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sort(a) { // Note: this doesn't work on strings.
|
function sort(a) {
|
||||||
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/sort
|
||||||
|
return a.sort;
|
||||||
|
/* // Note: this doesn't work on strings.
|
||||||
for(var i=0;i<a.length-1;i++) {
|
for(var i=0;i<a.length-1;i++) {
|
||||||
var min=i;
|
var min=i;
|
||||||
for(var j=i+1;j<a.length;j++)
|
for(var j=i+1;j<a.length;j++)
|
||||||
@@ -115,6 +128,7 @@ function sort(a) { // Note: this doesn't work on strings.
|
|||||||
if(min!=i) swap(a,i,min);
|
if(min!=i) swap(a,i,min);
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
function filter(p,xs) {
|
function filter(p,xs) {
|
||||||
@@ -124,7 +138,7 @@ function filter(p,xs) {
|
|||||||
return ys;
|
return ys;
|
||||||
}
|
}
|
||||||
|
|
||||||
function implode(cs) {
|
function implode(cs) { // array of strings to string
|
||||||
/*
|
/*
|
||||||
var s="";
|
var s="";
|
||||||
for(var i=0;i<cs.length;i++)
|
for(var i=0;i<cs.length;i++)
|
||||||
@@ -133,6 +147,9 @@ function implode(cs) {
|
|||||||
*/
|
*/
|
||||||
return cs.join("");
|
return cs.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasPrefix(s,pre) { return s.substr(0,pre.length)==pre; }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function all(p,xs) {
|
function all(p,xs) {
|
||||||
for(var i=0;i<xs.length;i++)
|
for(var i=0;i<xs.length;i++)
|
||||||
@@ -147,6 +164,9 @@ function map(f,xs) {
|
|||||||
return ys;
|
return ys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// map in continuation passing style
|
||||||
|
function mapc(f,xs,cont) { mapc_from(f,xs,0,[],cont); }
|
||||||
|
|
||||||
function mapc_from(f,xs,i,ys,cont) {
|
function mapc_from(f,xs,i,ys,cont) {
|
||||||
if(i<xs.length)
|
if(i<xs.length)
|
||||||
f(xs[i],function(y){ys[i]=y;mapc_from(f,xs,i+1,ys,cont)});
|
f(xs[i],function(y){ys[i]=y;mapc_from(f,xs,i+1,ys,cont)});
|
||||||
@@ -154,4 +174,19 @@ function mapc_from(f,xs,i,ys,cont) {
|
|||||||
cont(ys);
|
cont(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapc(f,xs,cont) { mapc_from(f,xs,0,[],cont); }
|
function overlaps(as,bs) {
|
||||||
|
for(var i=0;i<as.length;i++)
|
||||||
|
if(elem(as[i],bs)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function elem(a,as) {
|
||||||
|
for(var i=0;i<as.length;i++)
|
||||||
|
if(a==as[i]) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function shuffle(a) {
|
||||||
|
for(i=0;i<a.length;i++) swap(a,i,Math.floor(Math.random()*a.length))
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user