-
Notifications
You must be signed in to change notification settings - Fork 2
/
SPOT_custom_analysis_template.html
141 lines (109 loc) · 6.42 KB
/
SPOT_custom_analysis_template.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<html>
<head>
<title>Syntax prosody interface application</title>
<link rel="stylesheet" type="text/css" href="spot.css">
<script src="lib/jszip.min.js"></script>
<!-- to keep spot.js in sync with the codebase make sure to run jsbuild.sh after making any changes to javascript files in the main directory or in the constraints sub-directory
(open a terminal, cd into the main directory, type ./jsbuild.sh and hit enter) -->
<script src="build/spot.js"></script>
<script>
/*Custom constraints can be defined inside <script> tags, as here, or in a separate file which you can load, also using a script tag*/
function constraint1(stree, ptree, cat){
var vcount = 0;
//Code for going through the tree and evaluate for some structure goes here
return vcount;
}
</script>
<!--Change "YOUR_TREES_HERE" to the name of your tree file on the following line. Make sure your file is in main/trees-->
<script src="trees/YOUR_TREES_HERE.js"></script>
</head>
<body style="padding-left: 5%; padding-right: 5%; padding-top: 20px">
<h2>MY ANALYSIS: investigation using SPOT</h2>
<pre id="results-container"></pre>
<script>
// ---- Variables that need to be customized ----
// Options for auto-generating input syntactic trees
// see sTreeGEN() in inputCandidateGenerator.js):
// - rootCategory: default = 'xp'
// - recursiveCategory: default = 'xp'
// - terminalCategory: default = 'x0'
// - noAdjacentHeads: are x0 sisters allowed? [x0 x0]. Defaults to true.
// - noAdjuncts: are xp sisters allowed? [xp xp]. Defaults to false.
// - maxBranching: determines the maximum number of branches that are tolerated in
// the resulting syntactic trees. Default = 2
// - addClitics: 'right' or 'left' determines whether clitics are added on the
// righthand-side or the left; true will default to right. false doesn't add any clitics.
// Default false.
// - headSide: 'right', 'left', 'right-strict', 'left-strict'.
// Which side will heads be required to be on, relative to their complements?
// Also, must heads be at the very edge (strict)?
/*sTreeList is an array of syntactic trees. There are two options for getting the list of syntactic trees:
1. Recommended: Auto-generate a systematic set of syntactic trees using sTreeGEN()
2. Manually create and save trees (either in a separate tree file (trees/YOUR_TREES_HERE.js) or in this document), and list their variable names in the array.*/
//Option 1: Auto generation of trees (Recommended)
var sTreeOptions = {rootCategory:'xp', recursiveCategory: 'xp', terminalCategory: 'x0',
noAdjacentHeads: true, noAdjuncts: false,
maxBranching: 2, noUnary: false,
headSide: 'left', addClitics: false};
// Replace 'a b', 'a b c' with the terminal strings you are interested in
var terminalStrings = ['a b', 'a b c'];
var sTreeLists = Array(length=terminalStrings.length);
for(var i in terminalStrings){
sTreeLists[i] = sTreeGEN(terminalStrings[i], sTreeOptions);
}
var sTreeList = sTreeLists.flat();
//Option 2: Define trees manually
//var sTreeList = [sTree1, sTree2];
/*Constraint sets are defined below. You can change these or add your own. A constraint set is a list of constraint function names (refer to the files in constraints.js for names) + category arguments (separated from constraint names with -; refer to prosodicHierarchy.js for a list of defined categories).*/
var conMatch = ['matchSP-xp', 'matchPS-phi', 'equalSistersAdj-phi'];
var conAlign = ['alignRight-xp', 'alignLeft-xp', 'wrap-xp', 'equalSistersAdj-phi'];
//var conOther = ['constraint1-xp','constraint2-phi', 'constraint3-w', 'etc-i'];
/*A list of names for your constraint sets. These are used for naming the tableau csv files and finding the lists of constraint names. They need to match the variable names above.*/
var conNames = ['conMatch', 'conAlign'];
//Candidate sets are generated with the options below.
var gen_options = {obeysHeadedness: true, obeysNonrecursivity: false, obeysExhaustivity: false};
// ---- Functions that don't necessarily need to be customized ----
/*Function that concatenates a bunch of tableaux for various candidate sets into one large tableau. It does not need to be modified if you are only comparing different constraint sets. But it can be modified to deal with your particular analysis. For example, to consider multiple possible input syntaxes, you can add an outer for-loop to iterate over the different tree sets, as well as interating over the trees in each set.*/
function makeTableauCsvs(consName) {
var csvSegs = []; //List to accumulate tableaux in
//For each syntactic tree in sTreeList, make a tableau using the current constraint set
for(var j=0; j<sTreeList.length; j++){
var currentSTree = globalNameOrDirect(sTreeList[j]);
//Make the candidate set using the GEN function (defined in candidategenerator.js)
//Leave the 2nd argument as an empty string to scrape words from the terminals of the syntactic tree.
var candSet = GEN(sTreeList[j], '', gen_options);
//Make the tableau using the makeTableau function (defined in tableauMaker.js)
var tabl = makeTableau(candSet, window[consName]);
//Write the tableau to the screen and reveal it -- only uncomment this if you don't have too many tableaux!
//writeTableau(tabl)
//revealNextSegment();
//lastSegmentId++;
//Add the tableau from the current stree to cumulative tableau that is being built in csvSegs.
csvSegs.push(tableauToCsv(tabl, '\t', {noHeader: j}));
}
//Save the tableau as a tab-separated file, named after consName
saveTextAs(csvSegs.join('\n'),"tableau_"+consName+".csv");
}
/*This function executes automatically when the page is reloaded. It calls all the other functions.*/
function runDemo() {
//Iterate over the different constraint sets. Make a tableau for each one.
for(var i = 0; i<conNames.length; i++){
makeTableauCsvs(conNames[i]);
}
}
/*Utilities for saving files.*/
function saveAs(blob, name) {
var a = document.createElement("a");
a.display = "none";
a.href = URL.createObjectURL(blob);
a.download = name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function saveTextAs(text, name) {
saveAs(new Blob([text], {type: "text/csv", encoding: 'utf-8'}), name);
}
</script>
</body>
</html>