Commit 8ebe6a67 authored by Tom Gordon's avatar Tom Gordon

completed the first prototype of the argumentation tool

parent 963f5c71
......@@ -22,18 +22,18 @@ var AnimalsModel = domain.DomainModel{
},
"AC": &domain.Dimension{
Description: "Applicable Convention",
Factors: []string{"full-possession", "informal-excluse-right", "social-preference", "none"},
Default: "none",
Factors: []string{"full-possession", "informal-excluse-right", "social-preference", "ac-none"},
Default: "ac-none",
},
"COP": &domain.Dimension{
Description: "Closeness of Pursuit",
Factors: []string{"physical-possession", "mortal-wounding", "certain-capture", "hot-pursuit", "chasing", "started-pursuit", "none"},
Default: "none",
Factors: []string{"physical-possession", "mortal-wounding", "certain-capture", "hot-pursuit", "chasing", "started-pursuit", "cop-none"},
Default: "cop-none",
},
"QV": &domain.Dimension{
Description: "Quarry Value",
Factors: []string{"market-value", "social-value", "domestic-pet", "personal-value", "none"},
Default: "none",
Factors: []string{"market-value", "social-value", "domestic-pet", "personal-value", "qv-none"},
Default: "qv-none",
},
"QLC": &domain.Dimension{
Description: "Quarry Land Connection",
......
// Copyright © 2015 Thomas F. Gordon
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL
// was not distributed with this file, You can obtain one
// at http://mozilla.org/MPL/2.0/.
package web
import (
"bytes"
"github.com/carneades/carneades-4/src/engine/caes"
"github.com/carneades/carneades-4/src/engine/caes/encoding/dot"
"github.com/carneades/carneades-4/src/engine/caes/encoding/json"
"html/template"
"io/ioutil"
"net/http"
"os/exec"
"path"
)
func makeMapCaseHandler(couchdbURL string, dbName string, errorTemplate *template.Template, templatesDir string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
caseId := path.Base(req.URL.Path)
url := couchdbURL + dbName + "/" + caseId
resp, err := http.Get(url)
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
var cag *caes.ArgGraph
rd := bytes.NewReader(body)
cag, err = json.Import(rd)
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
cmd := exec.Command("dot", "-Tsvg")
w2 := bytes.NewBuffer([]byte{})
cmd.Stdin = w2
cmd.Stdout = w
err = dot.Export(w2, *cag)
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
w.Header().Set("Content-Type", "image/svg+xml; charset=utf-8")
// w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
err = cmd.Run()
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
}
}
......@@ -11,17 +11,17 @@ import (
"encoding/json"
// "fmt"
"git.list.lu/eagle/argumentation-tool/internal/animals"
"github.com/carneades/carneades-4/src/engine/caes"
"github.com/carneades/carneades-4/src/engine/caes/encoding/dot"
// "github.com/carneades/carneades-4/src/engine/caes"
// "github.com/carneades/carneades-4/src/engine/caes/encoding/dot"
cj "github.com/carneades/carneades-4/src/engine/caes/encoding/json"
"github.com/pborman/uuid"
"html/template"
"io/ioutil"
"net/http"
"os/exec"
// "os/exec"
)
func makeNewAnimalsCaseHandler(couchdbURL string, dbName string, errorTemplate *template.Template) func(w http.ResponseWriter, req *http.Request) {
func makeNewAnimalsCaseHandler(couchdbURL string, dbName string, errorTemplate, newCaseCreatedTemplate *template.Template) func(w http.ResponseWriter, req *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
ag := cj.NewArgGraph()
ag.Meta["title"] = req.FormValue("title")
......@@ -139,37 +139,7 @@ func makeNewAnimalsCaseHandler(couchdbURL string, dbName string, errorTemplate *
// stored in Couchdb, first read the JSON back in
// from the Couchdb repository.
resp, err = http.Get(couchdbURL + dbName + "/" + id)
defer resp.Body.Close()
var data []byte
data, err = ioutil.ReadAll(resp.Body)
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
newCaseCreatedTemplate.Execute(w, id)
var cag *caes.ArgGraph
rd := bytes.NewReader(data)
cag, err = cj.Import(rd)
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
cmd := exec.Command("dot", "-Tsvg")
w2 := bytes.NewBuffer([]byte{})
cmd.Stdin = w2
cmd.Stdout = w
err = dot.Export(w2, *cag)
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
err = cmd.Run()
if err != nil {
errorTemplate.Execute(w, err.Error())
return
}
}
}
......@@ -85,6 +85,11 @@ func makeSearchHandler(couchdbURL string, dbName string, errorTemplate *template
// The keys are the statement ids of the positions of the issue
caseTable := make(map[string][]SimilarCase)
// Initialize the table by adding a column for each position of the model
for _, p := range model.Issue {
caseTable[p] = []SimilarCase{}
}
// Compare each case with the current case and append it to
// the column of the case table for the position it supports.
for _, c := range data.Rows {
......
......@@ -13,8 +13,10 @@
<div data-role="page" id="CaseView">
<div data-role="header">
<h1>Case View</h1>
<h1>{{.Title}}</h1>
</div>
<div role="main" class="ui-content">
<h2>Properties</h2>
......@@ -43,28 +45,35 @@
<legend>Case Decision:</legend>
{{range $id, $position := .Positions}}
<input type="radio" name="decision" id="{{$id}}" value="{{$id}}" {{if $position.In}} checked="checked" {{end}}>
<label for="possession">Possession of the animal was acquired.</label>
<label for="{{$id}}">{{$position.Statement}}</label>
{{end}}
</fieldset>
<h2>Case Factors</h2>
<fieldset data-role="controlgroup">
{{range $id, $dimension := .Dimensions}}
<label for="text-basic">{{$dimension.Description}}</label>
<input name="text-basic" id="text-basic" value="{{$dimension.Factor}}" type="text">
<fieldset data-role="controlgroup">
<legend>{{$dimension.Description}}:</legend>
{{range $factor := $dimension.Factors}}
<input type="radio" name="{{$dimension.Id}}" id="{{$factor.Id}}" value="{{$factor.Id}}" {{if $factor.Selected}} checked="checked" {{end}}>
<label for="{{$factor.Id}}">{{$factor.Text}}</label>
{{end}}
</fieldset>
{{end}}
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="submit" value="Find Similar Cases"/>
<a href="/map-case/{{.Id}}" target="_self" class="ui-btn">Argument Map</a>
</fieldset>
<input type="submit" value="Find Similar Cases"/>
</form>
</div>
<div data-role="footer" data-id="main-footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a href="/" class="ui-btn-active" data-icon="home">Home</a></li>
<li><a href="/" class="ui-btn-active" data-icon="home">Home</a></li>
<li><a href="/eval-help" data-icon="info">Help</a></li>
<li><a href="/imprint" data-icon="info">Imprint</a></li>
<li><a href="/imprint" data-icon="info">Imprint</a></li>
</ul>
</div>
</div>
......
......@@ -247,14 +247,12 @@ case the fox, by pursuit. Source: Wikipedia
<label for="dr-solely-responsible">solely-responsible</label>
</fieldset>
<!--
<div data-role="controlgroup" data-type="horizontal">
<a class="ui-btn ui-corner-all" type="submit">Submit</a>
<a href="/" class="ui-btn ui-corner-all">Cancel</a>
</div>
-->
<!-- <button class="ui-shadow ui-btn ui-corner-all" type="submit" id="submit-new-animals-case"/>Submit</button> -->
<input type="submit" value="Submit"/>
<!-- <input type="submit" value="Submit"/> -->
<form>
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="submit" value="Submit"/>
</fieldset>
</form>
</form>
</div>
......
<!DOCTYPE html>
<html>
<head>
<title>New Case Created</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page" id="new-case-created">
<div data-role="header">
<h1>New Case Successfully Created!</h1>
</div>
<h2>Actions</h2>
<fieldset data-role="controlgroup" data-type="horizontal">
<a href="/view-case/{{.}}" class="ui-btn">View Case</a>
<a href="/map-case/{{.}}" class="ui-btn">Argument Map</a>
<a href="/" class="ui-btn" data-icon="home">Home</a>
</fieldset>
<div data-role="footer" data-id="main-footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a href="/" class="ui-btn-active" data-icon="home">Home</a></li>
<li><a href="help.html" data-icon="info">Help</a></li>
<li><a href="/imprint" data-icon="info">Imprint</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
......@@ -204,14 +204,11 @@
<label for="dr-solely-responsible">solely-responsible</label>
</fieldset>
<!--
<div data-role="controlgroup" data-type="horizontal">
<a class="ui-btn ui-corner-all" type="submit">Submit</a>
<a href="/" class="ui-btn ui-corner-all">Cancel</a>
</div>
-->
<!-- <button class="ui-shadow ui-btn ui-corner-all" type="submit" id="submit-new-animals-case"/>Submit</button> -->
<input type="submit" value="Submit"/>
<form>
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="submit" value="Find Similar Cases"/>
</fieldset>
</form>
</form>
</div>
......
......@@ -20,9 +20,9 @@
showing the most similar cases first.</p>
<div role="main" class="ui-content">
{{range $position, $cases := .}}
{{range $position, $cases := .}}
<h3>{{$position}}</h3>
{{if $cases}}
<table data-role="table" id="table-column-toggle" class="ui-responsive table-stroke">
<thead>
<tr>
......@@ -43,6 +43,9 @@
{{end}}
</tbody>
</table>
{{else}}
<p>No cases for this position</p>
{{end}}
{{end}}
</div>
<div data-role="footer" data-id="main-footer" data-position="fixed">
......
......@@ -8,9 +8,7 @@ package web
import (
"encoding/json"
"fmt"
"git.list.lu/eagle/argumentation-tool/internal/animals"
// "git.list.lu/eagle/argumentation-tool/internal/domain"
"html/template"
"io/ioutil"
"net/http"
......@@ -23,9 +21,16 @@ type Position struct {
In bool
}
type Factor struct {
Id string
Text string
Selected bool
}
type Dimension struct {
Id string
Description string
Factor string
Factors []Factor
}
func makeViewCaseHandler(couchdbURL string, dbName string, errorTemplate *template.Template, templatesDir string) func(http.ResponseWriter, *http.Request) {
......@@ -37,7 +42,6 @@ func makeViewCaseHandler(couchdbURL string, dbName string, errorTemplate *templa
caseId := path.Base(req.URL.Path)
url := couchdbURL + dbName + "/" + caseId
fmt.Printf("URL: %v\n", url)
resp, err := http.Get(url)
if err != nil {
errorTemplate.Execute(w, err.Error())
......@@ -50,9 +54,8 @@ func makeViewCaseHandler(couchdbURL string, dbName string, errorTemplate *templa
return
}
fmt.Printf("body: %v\n", string(body))
data := struct {
Id string `json:"_id"`
Meta struct {
Title string `json:"title"`
Citation string `json:"citation"`
......@@ -77,9 +80,8 @@ func makeViewCaseHandler(couchdbURL string, dbName string, errorTemplate *templa
return
}
fmt.Printf("data: %v\n", data)
currentCase := map[string]interface{}{
"Id": data.Id,
"Title": data.Meta.Title,
"Citation": data.Meta.Citation,
"Court": data.Meta.Court,
......@@ -99,7 +101,11 @@ func makeViewCaseHandler(couchdbURL string, dbName string, errorTemplate *templa
// assumption: at most one factor of each dimension is in
if ok && s.Label == "in" {
dimensions := currentCase["Dimensions"].(map[string]Dimension)
dimensions[d] = Dimension{Description: model.Dimensions[d].Name, Factor: s.Text}
factors := []Factor{}
for _, f := range model.Dimensions[d].Factors {
factors = append(factors, Factor{Id: f, Text: model.FactorStatement(f), Selected: f == k})
}
dimensions[d] = Dimension{Id: d, Description: model.Dimensions[d].Description, Factors: factors}
}
for _, p := range model.Issue {
if k == p {
......
......@@ -30,6 +30,7 @@ func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func ArgumentationToolServer(httpPort string, couchdbURL string, dbName string, templatesDir string) {
var errorTemplate = template.Must(template.ParseFiles(filepath.Join(templatesDir, "error.html")))
var newCaseCreatedTemplate = template.Must(template.ParseFiles(filepath.Join(templatesDir, "new-case-created.html")))
http.Handle("/", &templateHandler{filename: "argumentation-tool.html", templatesDir: templatesDir})
http.Handle("/help", &templateHandler{filename: "help.html", templatesDir: templatesDir})
http.Handle("/new-case-form", &templateHandler{filename: "new-case.html", templatesDir: templatesDir})
......@@ -37,12 +38,14 @@ func ArgumentationToolServer(httpPort string, couchdbURL string, dbName string,
http.Handle("/search-cases-form", &templateHandler{filename: "search-cases.html", templatesDir: templatesDir})
http.Handle("/search-animals-cases-form", &templateHandler{filename: "search-animals-cases.html", templatesDir: templatesDir})
http.Handle("/imprint", &templateHandler{filename: "imprint.html", templatesDir: templatesDir})
newAnimalsCaseHandler := makeNewAnimalsCaseHandler(couchdbURL, dbName, errorTemplate)
newAnimalsCaseHandler := makeNewAnimalsCaseHandler(couchdbURL, dbName, errorTemplate, newCaseCreatedTemplate)
http.HandleFunc("/new-animals-case", newAnimalsCaseHandler)
searchAnimalsCasesHandler := makeSearchHandler(couchdbURL, dbName, errorTemplate, templatesDir)
http.HandleFunc("/search-animals-cases", searchAnimalsCasesHandler)
viewCaseHandler := makeViewCaseHandler(couchdbURL, dbName, errorTemplate, templatesDir)
http.HandleFunc("/view-case/", viewCaseHandler)
mapCaseHandler := makeMapCaseHandler(couchdbURL, dbName, errorTemplate, templatesDir)
http.HandleFunc("/map-case/", mapCaseHandler)
// start the web server
if err := http.ListenAndServe(":"+httpPort, nil); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment