-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayTDdoc.php
executable file
·209 lines (176 loc) · 5.88 KB
/
displayTDdoc.php
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/* FUNCTIONS */
function & prepstring($strInput)
{
$punc = array(".", ",", "?", ";", ":", "(", ")", "[", "]");
$str1 = str_replace($punc, "", $strInput);
//$str2 = str_replace("'", "\'", $str1);
$str2 = strtolower($str1);
return $str2;
}
// function from PHP manual by Jesse Bussman at gmail
function explodeX($delimiters,$string)
{
$return_array = Array($string); // The array to return
$d_count = 0;
while (isset($delimiters[$d_count])) // Loop to loop through all delimiters
{
$new_return_array = Array();
foreach($return_array as $el_to_split) // Explode all returned elements by the next delimiter
{
$put_in_new_return_array = explode($delimiters[$d_count],$el_to_split);
foreach($put_in_new_return_array as $substr) // Put all the exploded elements in array to return
{
$new_return_array[] = $substr;
}
}
$return_array = $new_return_array; // Replace the previous return array by the next version
$d_count++;
}
return $return_array; // Return the exploded elements
}
function makeDocUrl($urlBase, $alchid, $title) {
$alcharray = array();
$alchpattern = "/^[ALCH0-9]+/";
preg_match($alchpattern, $alchid, $alcharray);
$alch = $alcharray[0];
$folioarray = array();
$foliopattern = "/f\.[0]*([0-9\.rv]+)/";
preg_match($foliopattern, $title, $folioarray);
$folio = $folioarray[1];
return $urlBase."text/".$alch."/diplomatic"."/#f".$folio;
}
/* STOP LISTS */
$stoplist =" PARAG[[ ]]PARAG EXPAN[[ ]]EXPAN REG[[ ]]REG [[LB]] HEAD[[ ]]HEAD LATIN[[ ]]LATIN ENGLISH[[ ]]ENGLISH FRENCH[[ ]]FRENCH NAME[[ ]]NAME ABBR[[ ]]ABBR CORR[[ ]]CORR";
$passlist =" ADD[[ ]]ADD HI[[ ]]HI FOLIO[[ ]]FOLIO . , ; : ? ( ) [ ] { } p p. p: ";
// open the database
$textSite = "";
$connection = new mysqli();
require_once("functions/mysql_connection.php");
/* PROGRAM SETUP */
$frags = "";
if (isset($_GET['frags']) && $_GET['frags'] != "")
{
$frags = $_GET['frags'];
}
if ($frags == "") {
return;
}
// identifying the documents
$doc = "";
if (isset($_GET['doc']) && $_GET['doc'] != "")
{
$doc = $_GET['doc'];
}
$term = "";
if (isset($_GET['term']) && $_GET['term'] != "")
{
$term = $_GET['term'];
}
// getting the correlation
$corr = "correlated chunks";
if (isset($_GET['corr']) && $_GET['corr'] != 0)
{
$corr = $_GET['corr'];
}
//begin setup
$getdocdata = "SELECT alch, ctitle, mstitle, ctext FROM frag250 WHERE id=".$doc;
if ($frags == "ch1000") {
$getdocdata = "SELECT alch, ctitle, mstitle, ctext FROM frag1000 WHERE id=".$doc;
}
$docdata = mysqli_query($connection, $getdocdata);
$docrow = mysqli_fetch_row($docdata);
$alch = $docrow[0];
$title = $docrow[1];
$mstitle = $docrow[2];
$dstring = $docrow[3];
// make document URLs
$docUrl = makeDocUrl($textSite, $alch, $title);
// pulling out the text
//$dstring = file_get_contents($sourcedir.$doc);
$d = explode("\n", $dstring);
$dsx = prepstring($dstring);
$dcheck = explodeX(Array(" ", "\n"), $dsx);
//zero out big strings that are no longer needed
$dstring = ""; $dsx = "";
// prep the $term variable for apostrophes, etc
$termx = str_replace("@", "'", $term);
$termstring = prepstring($termx);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="keywords" content="science,chemistry,history,isaac newton,chymistry,alchemical manuscripts,national science foundation,laboratory,chymistry of isaac newton,indiana university,digtial library,alchemy,newton">
<meta name="description" content="Isaac Newton, like Albert Einstein, is a quintessential symbol of the human intellect and its ability to decode the secrets of nature. Newton wrote and transcribed about a million words on the subject of alchemy, of which only a tiny fraction has today been published. With the support of the National Science Foundation and the National Endowment for the Humanities, The Chymistry of Isaac Newton hosted by Indiana University's Digital Library Program, is producing a scholarly online edition of Newton's alchemical manuscripts integrated with new research on Newton's chymistry.">
<meta name="author" content="Wallace Hooper">
<meta name="generator" content="tei2html stylesheets" />
<!-- Dublin Core Record: start -->
<meta name="DC.title" content="Latent Semantic Analysis Tool" />
<meta name="DC.creator" content="Wally Hooper">
<meta name="DC.designer" content="Timothy D Bowman">
<meta name="DC.type" scheme="DCTERMS.DCMIType" content="Text">
<meta name="DC.Format" scheme="DCTERMS.IMT" content="application/xhtml+xml">
<!-- Dublin Core Record: end -->
<title>LSA Results at <?php echo $corr; ?>: The Chymistry of Isaac Newton Project</title>
<?php require_once 'design/includes.php'; ?>
<!-- LSA Style -->
<link href="css.lsa/style.css" rel="stylesheet" media="all" />
<!-- End LSA Style -->
<style type="text/css" media="all">
.match {
background-color: yellow;
}
.content {
font-size: 0.8em;
}
</style>
</head>
<body>
<!-- Newton Skin -->
<?php require_once 'design/header.php'; ?>
<?php
echo "<div class='content'>";
echo "<a href='".$docUrl."' target='_blank'>".$docUrl." (new window)</a><br/><br/>";
echo "$alch<br/>$title<br/>$mstitle<br/><br/>";
foreach($d as $line1) {
$words1 = explode(" ", $line1);
foreach($words1 as $w1) {
if (strpos($stoplist, $w1) > 0)
{ continue; }
if (strpos($passlist, $w1) > 0)
{
print($w1." ");
continue;
}
$w1x = prepstring($w1);
$regexpattern = "/^".$w1x."$|^".$w1x."_|_".$w1x."_|_".$w1x."$/";
$regextest = preg_match($regexpattern, $termstring);
//if ($w1x == $term) {
if ($regextest) {
print("<span class=\"match\">$w1</span> ");
}
else {
print($w1." ");
}
}
print("<br/>");
}
echo "</div>";
?>
</section>
</div>
</div>
</section>
<!-- Newton Skin -->
<?php
require_once('design/page-footer.php');
require_once 'design/jsfooter.php';
?>
</body>
</html>
<?php
mysqli_free_result($docdata);
mysqli_free_result($docrow);
mysqli_close($connection);
?>