Page 1

The GF Cloud

GF Summer School 2013

Thomas Hallgren

Page 2

Purpose

Page 3

Where is the GF cloud

Page 4

What is in the GF cloud

Page 5

Some other web applications

Page 6

Application programming with GF grammars

Page 7

The Portable Grammar Format

Page 8

Haskell Applications

PGF run-time library

Page 9

Installing the PGF run-time library

Page 10
Installing the PGF run-time library

Example 1: a simple translator

Translator.hs

Page 11
Installing the PGF run-time library

Example 2: a question-answering system

Page 12
Installing the PGF run-time library → Example 2: a question-answering system

Abstract syntax in GF

abstract Arithmetic = {
    
flags startcat=Question ;

cat Answer; Object; Question;

fun Even, Odd, Prime : Object -> Question;
    Number : Int -> Object;

    Yes, No : Answer;
}
Page 13
Installing the PGF run-time library → Example 2: a question-answering system

Concrete syntax for English

concrete ArithmeticEng of Arithmetic = {

lincat
    Answer, Object, Question = Str;

lin Even object = is "even" object;
    Odd object = is "odd" object;
    Prime object = is "prime" object;
    Number int = int.s;
    No  = "No.";
    Yes  = "Yes.";

oper is : Str -> Str -> Str  = \ pred,obj -> "is"++obj++pred++"?";
}
Page 14
Installing the PGF run-time library → Example 2: a question-answering system

Haskell code

Similar to the translator example, but

Page 15
Installing the PGF run-time library → Example 2: a question-answering system → Haskell code
Page 16
Installing the PGF run-time library → Example 2: a question-answering system

Exporting GF abstract syntax to Haskell

Page 17
Installing the PGF run-time library → Example 2: a question-answering system

Generated Haskell Code

Page 18
Installing the PGF run-time library → Example 2: a question-answering system

Transfer function

Page 19
Installing the PGF run-time library → Example 2: a question-answering system → Transfer function

Compile with:
ghc --make Answer.hs

Page 20
Installing the PGF run-time library

Example 3

A larger query language

Larger grammar: Query.gf, MathQuery.gf, QueryEng.gf, MathQueryEng.gf

Page 21

Implementing web applications using GF

Page 22

Server-side GF applications

Page 23
Server-side GF applications

Implementation: server side

Page 24
Server-side GF applications

Implementation: client side

Some HMTL+JavaScript to submit questions and embed the answer in the same web page

Page 25

PGF web service API

Page 26

GF JavaScript library

Page 27

Running the PGF service on your own computer

GF server mode

Page 28
Running the PGF service on your own computer

Example

Question answering with guided input:

Page 29
Running the PGF service on your own computer

FastCGI with Lighttpd / Apache httpd

Page 30

Web applications without a web server

Translating grammars to JavaScript, example:

Page 31
Web applications without a web server

Minibar offline experiment (November 2010)

Page 32

Applications in other languages

Page 33

The End

Questions?

More info