Commit d3854c89 authored by Tom Gordon's avatar Tom Gordon

started work on the search functions

parent 8d994feb
......@@ -22,6 +22,7 @@ var goPath = os.Getenv("GOPATH")
const defaultPort = "8080"
const defaultCouchdbURL = "http://127.0.0.1:5984/"
const dbName = "cases"
var templatesDir = filepath.Join(goPath, "/src/git.list.lu/argumentation-tool/internal/web/templates/")
......@@ -33,5 +34,5 @@ func main() {
log.Fatal(err)
}
web.ArgumentationToolServer(*httpPort, *couchdbURL, templatesDir)
web.ArgumentationToolServer(*httpPort, *couchdbURL, dbName, templatesDir)
}
......@@ -22,9 +22,7 @@ func toEnglish(atom string) string {
var dimensions = []string{"LO", "AC", "COP", "QV", "QLC", "NOA", "PM", "DM", "DR"}
const dbName = "cases"
func makeNewAnimalsCaseHandler(couchdbURL string, errorTemplate *template.Template) func(w http.ResponseWriter, req *http.Request) {
func makeNewAnimalsCaseHandler(couchdbURL string, dbName string, errorTemplate *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")
......@@ -114,6 +112,8 @@ func makeNewAnimalsCaseHandler(couchdbURL string, errorTemplate *template.Templa
}
defer resp.Body.Close()
// check that uploading was successful
m := make(map[string]interface{})
v, err := ioutil.ReadAll(resp.Body)
if err != nil {
......@@ -129,6 +129,11 @@ func makeNewAnimalsCaseHandler(couchdbURL string, errorTemplate *template.Templa
// m should have the form:
// {"ok":true,"id":"6e1295ed6c29495e54cc05947f18c8af","rev":"1-2902191555"}
if m["ok"] != true {
errorTemplate.Execute(w, "Saving the case to Couchdb failed")
return
}
// Provide the user with feedback by displaying an
// argument map, in SVG formt, for the argument graph of the
// case entered. To validate that the graph has been correctly
......
package web
import (
// "fmt"
"github.com/carneades/carneades-4/src/engine/caes"
// cj "github.com/carneades/carneades-4/src/engine/caes/encoding/json"
"html/template"
"net/http"
"path/filepath"
)
type SimilarCase struct {
idd string
Title string
Year string
Similarity float64
}
func makeSearchHandler(couchdbURL string, dbName string, errorTemplate *template.Template, templatesDir string, issue string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
t := template.Must(template.ParseFiles(filepath.Join(templatesDir, "search-results.html")))
t.Execute(w, v)
}
}
......@@ -16,14 +16,14 @@
</div>
<ul data-role="listview" data-inset="true">
<li><a href="/new-animals-case-form">Enter a new case about the possession of wild animals.</a></li>
<li><a href="/search-animals-cases-form">Search for cases about the possession of wild animals. </a></li>
<li><a href="/new-case-form">Enter a new case</a></li>
<li><a href="/search-cases-form">Search for similar cases</a></li>
</ul>
<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="/help" data-icon="info">Help</a></li>
<li><a href="/imprint" data-icon="info">Imprint</a></li>
</ul>
......
<!DOCTYPE html>
<html>
<head>
<title>EAGLE Argumentation Tool: New Case Form</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="NewCaseForm">
<div data-role="header">
<h1>New Case</h1>
</div>
<div role="main" class="ui-content">
<h2>Select the issue:</h2>
<ul data-role="listview">
<li><a href="/new-animals-case-form">Possession of Wild Animals</a></li>
</ul>
</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="/eval-help" data-icon="info">Help</a></li>
<li><a href="/imprint" data-icon="info">Imprint</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>EAGLE Argumentation Tool: Search Animals Cases Form</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="SearchAnimalsCasesForm">
<div data-role="header">
<h1>Search for similar wild animal possession cases</h1>
</div>
<div role="main" class="ui-content">
<form action="/search-animals-cases" enctype="multipart/form-data" target="_blank" data-ajax="false" method="post">
<h2>Case Factors</h2>
<fieldset data-role="controlgroup">
<legend>Land Ownership:</legend>
<input type="radio" name="LO" id="p-freehold" value="p-freehold" checked="checked">
<label for="p-freehold">p-freehold</label>
<input type="radio" name="LO" id="p-leasehold" value="p-leasehold">
<label for="p-leasehold">p-leasehold</label>
<input type="radio" name="LO" id="p-rent" value="p-rent">
<label for="p-rent">p-rent</label>
<input type="radio" name="LO" id="common" value="common">
<label for="common">common</label>
<input type="radio" name="LO" id="other-owner" value="other-owner">
<label for="other-owner">other-owner</label>
<input type="radio" name="LO" id="d-rent" value="d-rent">
<label for="d-rent">d-rent</label>
<input type="radio" name="LO" id="d-leasehold" value="d-leasehold">
<label for="d-leasehold">d-leasehold</label>
<input type="radio" name="LO" id="d-freehold" value="d-freehold">
<label for="d-freehold">d-freehold</label>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Applicable Convention:</legend>
<input type="radio" name="AC" id="full-possession" value="full-possession" checked="checked">
<label for="full-possession">full-possession</label>
<input type="radio" name="AC" id="informal-exclusive-right" value="informal-exclusive-right">
<label for="informal-exclusive-right">informal-exclusive-right</label>
<input type="radio" name="AC" id="social-preference" value="social-preference">
<label for="social-preference">social-preference</label>
<input type="radio" name="AC" id="ac-none" value="ac-none">
<label for="ac-none">None</label>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Closeness of Pursuit:</legend>
<input type="radio" name="COP" id="physical-possession" value="physical-possession" checked="checked">
<label for="physical-possession">physical-possession</label>
<input type="radio" name="COP" id="mortal-wounding" value="mortal-wounding">
<label for="mortal-wounding">mortal-wounding</label>
<input type="radio" name="COP" id="certain-capture" value="certain-capture">
<label for="certain-capture">certain-capture</label>
<input type="radio" name="COP" id="hot-pursuit" value="hot-pursuit">
<label for="hot-pursuit">hot-pursuit</label>
<input type="radio" name="COP" id="chasing" value="chasing">
<label for="chasing">chasing</label>
<input type="radio" name="COP" id="started-pursuit" value="started-pursuit">
<label for="started-pursuit">started-pursuit</label>
<input type="radio" name="COP" id="cop-none" value="cop-none">
<label for="cop-none">None</label>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Quarry Value:</legend>
<input type="radio" name="QV" id="market-value" value="market-value" checked="checked">
<label for="market-value">market-value</label>
<input type="radio" name="QV" id="social-value" value="social-value">
<label for="social-value">social-value</label>
<input type="radio" name="QV" id="domestic-pet" value="domestic-pet">
<label for="domestic-pet">domestic-pet</label>
<input type="radio" name="QV" id="personal-value" value="personal-value">
<label for="personal-value">personal-value</label>
<input type="radio" name="QV" id="qv-none" value="qv-none">
<label for="qv-none">None</label>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Quarry Land Connection:</legend>
<input type="radio" name="QLC" id="resident" value="resident" checked="checked">
<label for="resident">resident</label>
<input type="radio" name="QLC" id="frequent-visitor" value="frequent-visitor">
<label for="frequent-visitor">frequent-visitor</label>
<input type="radio" name="QLC" id="regular-visitor" value="regular-visitor">
<label for="regular-visitor">regular-visitor</label>
<input type="radio" name="QLC" id="occasional-visitor" value="occasional-visitor">
<label for="occasional-visitor">occasional-visitor</label>
<input type="radio" name="QLC" id="transient" value="transient">
<label for="transient">transient</label>
<input type="radio" name="QLC" id="once-only" value="once-only">
<label for="once-only">once-only</label>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Nature of Act:</legend>
<input type="radio" name="NOA" id="violently-illegal" value="violently-illegal" checked="checked">
<label for="violently-illegal">violently-illegal</label>
<input type="radio" name="NOA" id="illegal" value="illegal">
<label for="illegal">illegal</label>
<input type="radio" name="NOA" id="nuisance" value="nuisance">
<label for="nuisance">nuisance</label>
<input type="radio" name="NOA" id="impolite" value="impolite">
<label for="impolite">impolite</label>
<input type="radio" name="NOA" id="act-ok" value="act-ok">
<label for="act-ok">act-ok</label>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Motive of Party Claiming Possession:</legend>
<input type="radio" name="PM" id="pm-livelihood" value="pm-livelihood" checked="checked">
<label for="pm-livelihood">livelihood</label>
<input type="radio" name="PM" id="pm-opportunistic" value="pm-opportunistic">
<label for="pm-opportunistic">opportunistic</label>
<input type="radio" name="PM" id="pm-altruism" value="pm-altruism">
<label for="pm-altruism">altruism</label>
<input type="radio" name="PM" id="pm-pleasure" value="pm-pleasure">
<label for="pm-pleasure">pleasure</label>
<input type="radio" name="PM" id="pm-impulse" value="pm-impulse">
<label for="pm-impulse">impulse</label>
<input type="radio" name="PM" id="pm-malice" value="pm-malice">
<label for="pm-malice">malice</label>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Motive of Party Denying Claim of Possession:</legend>
<input type="radio" name="DM" id="dm-livelihood" value="dm-livelihood" checked="checked">
<label for="dm-livelihood">livelihood</label>
<input type="radio" name="DM" id="dm-opportunistic" value="dm-opportunistic">
<label for="dm-opportunistic">opportunistic</label>
<input type="radio" name="DM" id="dm-altruism" value="dm-altruism">
<label for="dm-altruism">altruism</label>
<input type="radio" name="DM" id="dm-pleasure" value="dm-pleasure">
<label for="dm-pleasure">pleasure</label>
<input type="radio" name="DM" id="dm-impulse" value="dm-impulse">
<label for="dm-impulse">impulse</label>
<input type="radio" name="DM" id="dm-malice" value="dm-malice">
<label for="dm-malice">malice</label>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Role of the Party Denying Claim of Possession:</legend>
<input type="radio" name="DR" id="dr-innocent" value="dr-innocent" checked="checked">
<label for="dr-innocent">innocent</label>
<input type="radio" name="DR" id="dr-jointly-responsible" value="dr-jointly-responsible">
<label for="dr-jointly-responsible">jointly-responsible</label>
<input type="radio" name="DR" id="dr-ignorant-of-law" value="dr-ignorant-of-law">
<label for="dr-ignorant-of-law">ignorant-of-law</label>
<input type="radio" name="DR" id="dr-accident" value="dr-accident">
<label for="dr-accident">accident</label>
<input type="radio" name="DR" id="dr-solely-responsible" value="dr-solely-responsible">
<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>
</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="/eval-help" data-icon="info">Help</a></li>
<li><a href="/imprint" data-icon="info">Imprint</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>EAGLE Argumentation Tool: Search Cases Form</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="SearchCasesForm">
<div data-role="header">
<h1>New Case</h1>
</div>
<div role="main" class="ui-content">
<h2>Select the issue:</h2>
<ul data-role="listview">
<li><a href="/search-animals-cases-form">Possession of Wild Animals</a></li>
</ul>
</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="/eval-help" data-icon="info">Help</a></li>
<li><a href="/imprint" data-icon="info">Imprint</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>EAGLE Argumentation Tool: Search Results</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="SearchResults">
<div data-role="header">
<h1>Similar Cases Found</h1>
</div>
<p>The most similar pro and con cases are listed, in order of similarity,
showing the more similar cases first. At most ten cases each,
pro and con, are listed.</p>
<div role="main" class="ui-content">
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<div class="ui-body ui-body-a ui-corner-all">
<h3>Pro Cases</h3>
<table data-role="table" id="table-column-toggle" class="ui-responsive table-stroke">
<thead>
<tr>
<th data-priority="2">Rank</th>
<th>Title</th>
<th data-priority="3">Year</th>
<th data-priority="4">Similarity</th>
</tr>
</thead>
<tbody>
<tr>
<th>1</th>
<td><a href="http://en.wikipedia.org/wiki/Citizen_Kane" data-rel="external">Citizen Kane</a></td>
<td>1941</td>
<td>74</td>
</tr>
<tr>
<th>2</th>
<td><a href="http://en.wikipedia.org/wiki/Casablanca_(film)" data-rel="external">Casablanca</a></td>
<td>1942</td>
<td>64</td>
</tr>
<tr>
<th>3</th>
<td><a href="http://en.wikipedia.org/wiki/The_Godfather" data-rel="external">The Godfather</a></td>
<td>1972</td>
<td>87</td>
</tr>
<tr>
<th>4</th>
<td><a href="http://en.wikipedia.org/wiki/Gone_with_the_Wind_(film)" data-rel="external">Gone with the Wind</a></td>
<td>1939</td>
<td>87</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="ui-block-b">
<div class="ui-body ui-body-a ui-corner-all">
<h3>Con Cases</h3>
<table data-role="table" id="table-column-toggle" class="ui-responsive table-stroke">
<thead>
<tr>
<th data-priority="2">Rank</th>
<th>Title</th>
<th data-priority="3">Year</th>
<th data-priority="4">Similarity</th>
</tr>
</thead>
<tbody>
<tr>
<th>1</th>
<td><a href="http://en.wikipedia.org/wiki/Citizen_Kane" data-rel="external">Citizen Kane</a></td>
<td>1941</td>
<td>74</td>
</tr>
<tr>
<th>2</th>
<td><a href="http://en.wikipedia.org/wiki/Casablanca_(film)" data-rel="external">Casablanca</a></td>
<td>1942</td>
<td>64</td>
</tr>
<tr>
<th>3</th>
<td><a href="http://en.wikipedia.org/wiki/The_Godfather" data-rel="external">The Godfather</a></td>
<td>1972</td>
<td>87</td>
</tr>
<tr>
<th>4</th>
<td><a href="http://en.wikipedia.org/wiki/Gone_with_the_Wind_(film)" data-rel="external">Gone with the Wind</a></td>
<td>1939</td>
<td>87</td>
</tr>
</tbody>
</table>
</div>
</div>
</fieldset>
</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="/eval-help" data-icon="info">Help</a></li>
<li><a href="/imprint" data-icon="info">Imprint</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
......@@ -22,18 +22,19 @@ func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
t.templ.Execute(w, nil)
}
func ArgumentationToolServer(httpPort string, couchdbURL string, templatesDir string) {
func ArgumentationToolServer(httpPort string, couchdbURL string, dbName string, templatesDir string) {
var errorTemplate = template.Must(template.ParseFiles(filepath.Join(templatesDir, "error.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})
http.Handle("/new-animals-case-form", &templateHandler{filename: "new-animals-case.html", templatesDir: templatesDir})
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, errorTemplate)
newAnimalsCaseHandler := makeNewAnimalsCaseHandler(couchdbURL, dbName, errorTemplate)
http.HandleFunc("/new-animals-case", newAnimalsCaseHandler)
// http.HandleFunc("/search-animals-cases", searchAnimalsCasesHandler)
searchAnimalsCasesHandler := makeSearchHandler(couchdbURL, dbName, errorTemplate, templatesDir, "possession of wild animals")
http.Handle("/search-animals-cases", &templateHandler{filename: "search-results.html", templatesDir: templatesDir})
// 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