81764
|
1 |
/* Title: Tools/Find_Facts.scala
|
|
2 |
Author: Fabian Huch, TU Muenchen
|
|
3 |
|
|
4 |
Full-text search engine for Isabelle (including web server), using Solr as backend.
|
|
5 |
*/
|
81770
|
6 |
|
|
7 |
package isabelle.find_facts
|
81764
|
8 |
|
|
9 |
|
81770
|
10 |
import isabelle._
|
|
11 |
|
81764
|
12 |
import scala.annotation.tailrec
|
|
13 |
import scala.collection.immutable.TreeMap
|
|
14 |
import scala.collection.mutable
|
|
15 |
|
|
16 |
|
|
17 |
object Find_Facts {
|
|
18 |
/** blocks **/
|
|
19 |
|
|
20 |
object Kind {
|
|
21 |
val CONST = "constant"
|
|
22 |
val TYPE = "type"
|
|
23 |
val THM = "fact"
|
|
24 |
}
|
|
25 |
|
|
26 |
case class Block(
|
|
27 |
id: String,
|
|
28 |
version: Long,
|
|
29 |
chapter: String,
|
|
30 |
session: String,
|
|
31 |
theory: String,
|
|
32 |
file: String,
|
|
33 |
url_path: Path,
|
|
34 |
command: String,
|
|
35 |
start_line: Int,
|
|
36 |
src_before: String,
|
|
37 |
src: String,
|
|
38 |
src_after: String,
|
|
39 |
xml: XML.Body,
|
|
40 |
html: String,
|
|
41 |
entity_kname: Option[String],
|
|
42 |
consts: List[String],
|
|
43 |
typs: List[String],
|
|
44 |
thms: List[String]
|
|
45 |
) {
|
|
46 |
def path = Path.explode(file)
|
|
47 |
def file_type: String = path.get_ext
|
|
48 |
def file_name: String = path.file_name
|
|
49 |
|
|
50 |
def kinds: List[String] =
|
|
51 |
(if (typs.nonEmpty) List(Kind.TYPE) else Nil) :::
|
|
52 |
(if (consts.nonEmpty) List(Kind.CONST) else Nil) :::
|
|
53 |
(if (thms.nonEmpty) List(Kind.THM) else Nil)
|
|
54 |
def names: List[String] = (typs ::: consts ::: thms).distinct
|
|
55 |
}
|
|
56 |
|
|
57 |
case class Blocks(num_found: Long, blocks: List[Block], cursor: String)
|
|
58 |
|
|
59 |
|
|
60 |
/** queries */
|
|
61 |
|
|
62 |
enum Atom {
|
|
63 |
case Exact(s: String) extends Atom
|
|
64 |
case Value(s: String) extends Atom
|
|
65 |
}
|
|
66 |
|
|
67 |
enum Field {
|
|
68 |
case chapter, session, file_type, theory, command, source, names, consts, typs, thms, kinds
|
|
69 |
}
|
|
70 |
|
|
71 |
sealed trait Filter
|
|
72 |
case class Field_Filter(field: Field, either: List[Atom]) extends Filter
|
|
73 |
case class Any_Filter(either: List[Atom]) extends Filter {
|
|
74 |
def fields: List[Field] = List(Field.session, Field.theory, Field.source, Field.names)
|
|
75 |
}
|
|
76 |
|
|
77 |
case class Select(field: Field, values: List[String])
|
|
78 |
|
|
79 |
object Query {
|
|
80 |
def apply(filters: Filter*): Query = new Query(filters.toList)
|
|
81 |
}
|
|
82 |
|
|
83 |
case class Query(
|
|
84 |
filters: List[Filter] = Nil,
|
|
85 |
exclude: List[Filter] = Nil,
|
|
86 |
selects: List[Select] = Nil)
|
|
87 |
|
|
88 |
|
|
89 |
/* stats and facets */
|
|
90 |
|
|
91 |
case class Stats(
|
|
92 |
results: Long,
|
|
93 |
sessions: Long,
|
|
94 |
theories: Long,
|
|
95 |
commands: Long,
|
|
96 |
consts: Long,
|
|
97 |
typs: Long,
|
|
98 |
thms: Long)
|
|
99 |
|
|
100 |
case class Facets(
|
|
101 |
chapter: Map[String, Long],
|
|
102 |
session: Map[String, Long],
|
|
103 |
theory: Map[String, Long],
|
|
104 |
file_type: Map[String, Long],
|
|
105 |
command: Map[String, Long],
|
|
106 |
kinds: Map[String, Long],
|
|
107 |
consts: Map[String, Long],
|
|
108 |
typs: Map[String, Long],
|
|
109 |
thms: Map[String, Long])
|
|
110 |
|
|
111 |
|
|
112 |
/** Solr data model **/
|
|
113 |
|
|
114 |
object private_data extends Solr.Data("find_facts") {
|
|
115 |
/* types */
|
|
116 |
|
|
117 |
val symbol_codes =
|
|
118 |
for {
|
|
119 |
entry <- Symbol.symbols.entries
|
|
120 |
code <- entry.decode.toList
|
|
121 |
input <- entry.symbol :: entry.abbrevs
|
|
122 |
} yield input -> code
|
|
123 |
|
|
124 |
val replacements =
|
|
125 |
for ((symbol, codes) <- symbol_codes.groupMap(_._1)(_._2).toList if codes.length == 1)
|
|
126 |
yield symbol -> Library.the_single(codes)
|
|
127 |
|
|
128 |
val Special_Char = """(.*[(){}\[\].,:"].*)""".r
|
|
129 |
val Arrow = """(.*=>.*)""".r
|
|
130 |
|
|
131 |
val synonyms =
|
|
132 |
for {
|
|
133 |
(symbol, code) <- symbol_codes
|
|
134 |
if !Special_Char.matches(symbol) && !Arrow.matches(symbol)
|
|
135 |
} yield symbol + " => " + code
|
|
136 |
|
|
137 |
override lazy val more_config = Map(Path.basic("synonyms.txt") -> synonyms.mkString("\n"))
|
|
138 |
|
|
139 |
object Types {
|
|
140 |
private val strip_html = Solr.Class("charFilter", "HTMLStripCharFilterFactory")
|
|
141 |
private val replace_symbol_chars =
|
|
142 |
replacements.collect {
|
|
143 |
case (Special_Char(pattern), code) =>
|
|
144 |
Solr.Class(
|
|
145 |
"charFilter", "PatternReplaceCharFilterFactory",
|
|
146 |
List("pattern" -> ("\\Q" + pattern + "\\E"), "replacement" -> code))
|
|
147 |
}
|
|
148 |
|
|
149 |
private val symbol_pattern =
|
|
150 |
"""\s*(::|[(){}\[\].,:"]|[^\p{ASCII}]|((?![^\p{ASCII}])[^(){}\[\].,:"\s])+)\s*""".r
|
|
151 |
|
|
152 |
private val tokenize =
|
|
153 |
Solr.Class("tokenizer", "WhitespaceTokenizerFactory", List("rule" -> "java"))
|
|
154 |
private val tokenize_symbols =
|
|
155 |
Solr.Class("tokenizer", "PatternTokenizerFactory",
|
|
156 |
List("pattern" -> symbol_pattern.toString, "group" -> "1"))
|
|
157 |
|
|
158 |
private val to_lower = Solr.Class("filter", "LowerCaseFilterFactory")
|
|
159 |
private val add_ascii =
|
|
160 |
Solr.Class("filter", "ASCIIFoldingFilterFactory", List("preserveOriginal" -> "true"))
|
|
161 |
private val delimit_words =
|
|
162 |
Solr.Class("filter", "WordDelimiterGraphFilterFactory", List(
|
|
163 |
"splitOnCaseChange" -> "0", "stemEnglishPossessive" -> "0", "preserveOriginal" -> "1"))
|
|
164 |
private val flatten = Solr.Class("filter", "FlattenGraphFilterFactory")
|
|
165 |
private val replace_symbols =
|
|
166 |
Solr.Class("filter", "SynonymGraphFilterFactory", List("synonyms" -> "synonyms.txt"))
|
|
167 |
private val replace_special_symbols =
|
|
168 |
replacements.collect {
|
|
169 |
case (Arrow(arrow), code) =>
|
|
170 |
Solr.Class("filter", "PatternReplaceFilterFactory",
|
|
171 |
List("pattern" -> ("\\Q" + arrow + "\\E"), "replacement" -> code))
|
|
172 |
}
|
|
173 |
|
|
174 |
val source =
|
|
175 |
Solr.Type("name", "TextField", Nil, List(
|
|
176 |
XML.Elem(Markup("analyzer", List("type" -> "index")),
|
|
177 |
List(strip_html, tokenize_symbols, to_lower, add_ascii, delimit_words, flatten)),
|
|
178 |
XML.Elem(
|
|
179 |
Markup("analyzer", List("type" -> "query")),
|
|
180 |
replace_symbol_chars ::: tokenize_symbols :: replace_symbols ::
|
|
181 |
replace_special_symbols ::: to_lower :: Nil)))
|
|
182 |
|
|
183 |
val name =
|
|
184 |
Solr.Type("source", "TextField", Nil, List(
|
|
185 |
XML.Elem(Markup("analyzer", List("type" -> "index")),
|
|
186 |
List(tokenize, to_lower, delimit_words, flatten)),
|
|
187 |
XML.Elem(Markup("analyzer", List("type" -> "query")), List(tokenize, to_lower))))
|
|
188 |
|
|
189 |
val text = Solr.Type("text", "TextField")
|
|
190 |
}
|
|
191 |
|
|
192 |
|
|
193 |
/* fields */
|
|
194 |
|
|
195 |
object Fields {
|
|
196 |
val id = Solr.Field("id", Solr.Type.string).make_unique_key
|
|
197 |
val version = Solr.Field("version", Solr.Type.long, Solr.Column_Wise(true))
|
|
198 |
val chapter = Solr.Field("chapter", Solr.Type.string, Solr.Column_Wise(true))
|
|
199 |
val session = Solr.Field("session", Types.name)
|
|
200 |
val session_facet = Solr.Field("session_facet", Solr.Type.string, Solr.Stored(false))
|
|
201 |
val theory = Solr.Field("theory", Types.name)
|
|
202 |
val theory_facet = Solr.Field("theory_facet", Solr.Type.string, Solr.Stored(false))
|
|
203 |
val file = Solr.Field("file", Solr.Type.string, Solr.Indexed(false))
|
|
204 |
val file_type =
|
|
205 |
Solr.Field("file_type", Solr.Type.string, Solr.Column_Wise(true) ::: Solr.Stored(false))
|
|
206 |
val url_path = Solr.Field("url_path", Solr.Type.string, Solr.Indexed(false))
|
|
207 |
val command = Solr.Field("command", Solr.Type.string, Solr.Column_Wise(true))
|
|
208 |
val start_line = Solr.Field("start_line", Solr.Type.int, Solr.Column_Wise(true))
|
|
209 |
val src_before = Solr.Field("src_before", Solr.Type.string, Solr.Indexed(false))
|
|
210 |
val src_after = Solr.Field("src_after", Solr.Type.string, Solr.Indexed(false))
|
|
211 |
val src = Solr.Field("src", Types.source)
|
|
212 |
val xml = Solr.Field("xml", Solr.Type.bytes, Solr.Indexed(false))
|
|
213 |
val html = Solr.Field("html", Solr.Type.bytes, Solr.Indexed(false))
|
|
214 |
val entity_kname = Solr.Field("entity_kname", Solr.Type.string, Solr.Indexed(false))
|
|
215 |
val consts = Solr.Field("consts", Types.name, Solr.Multi_Valued(true))
|
|
216 |
val consts_facet =
|
|
217 |
Solr.Field("consts_facet", Solr.Type.string, Solr.Multi_Valued(true) ::: Solr.Stored(false))
|
|
218 |
val typs = Solr.Field("typs", Types.name, Solr.Multi_Valued(true))
|
|
219 |
val typs_facet =
|
|
220 |
Solr.Field("typs_facet", Solr.Type.string, Solr.Multi_Valued(true) ::: Solr.Stored(false))
|
|
221 |
val thms = Solr.Field("thms", Types.name, Solr.Multi_Valued(true))
|
|
222 |
val thms_facet =
|
|
223 |
Solr.Field("thms_facet", Solr.Type.string, Solr.Multi_Valued(true) ::: Solr.Stored(false))
|
|
224 |
val names = Solr.Field("names", Types.name, Solr.Multi_Valued(true) ::: Solr.Stored(false))
|
|
225 |
val kinds =
|
|
226 |
Solr.Field("kinds", Solr.Type.string,
|
|
227 |
Solr.Multi_Valued(true) ::: Solr.Column_Wise(true) ::: Solr.Stored(false))
|
|
228 |
}
|
|
229 |
|
|
230 |
lazy val fields: Solr.Fields = Solr.Fields(
|
|
231 |
Fields.id, Fields.version, Fields.chapter, Fields.session, Fields.session_facet,
|
|
232 |
Fields.theory, Fields.theory_facet, Fields.file, Fields.file_type, Fields.url_path,
|
|
233 |
Fields.command, Fields.start_line, Fields.src_before, Fields.src_after, Fields.src,
|
|
234 |
Fields.xml, Fields.html, Fields.entity_kname, Fields.consts, Fields.consts_facet, Fields.typs,
|
|
235 |
Fields.typs_facet, Fields.thms, Fields.thms_facet, Fields.names, Fields.kinds)
|
|
236 |
|
|
237 |
|
|
238 |
/* operations */
|
|
239 |
|
|
240 |
def read_domain(db: Solr.Database, q: Solr.Source): Set[String] =
|
|
241 |
db.execute_query(Fields.id, List(Fields.id), None, 100000,
|
|
242 |
{ results =>
|
|
243 |
results.map(_.string(Fields.id)).toSet
|
|
244 |
}, q = q)
|
|
245 |
|
|
246 |
def read_block(res: Solr.Result): Block = {
|
|
247 |
val id = res.string(Fields.id)
|
|
248 |
val version = res.long(Fields.version)
|
|
249 |
val chapter = res.string(Fields.chapter)
|
|
250 |
val session = res.string(Fields.session)
|
|
251 |
val theory = res.string(Fields.theory)
|
|
252 |
val file = res.string(Fields.file)
|
|
253 |
val url_path = Path.explode(res.string(Fields.url_path))
|
|
254 |
val command = res.string(Fields.command)
|
|
255 |
val start_line = res.int(Fields.start_line)
|
|
256 |
val src_before = res.string(Fields.src_before)
|
|
257 |
val src = res.string(Fields.src)
|
|
258 |
val src_after = res.string(Fields.src_after)
|
|
259 |
val xml = YXML.parse_body(res.bytes(Fields.xml))
|
|
260 |
val html = res.bytes(Fields.html).text
|
|
261 |
val entity_kname = res.get_string(Fields.entity_kname)
|
|
262 |
val consts = res.list_string(Fields.consts)
|
|
263 |
val typs = res.list_string(Fields.typs)
|
|
264 |
val thms = res.list_string(Fields.thms)
|
|
265 |
|
|
266 |
Block(id = id, version = version, chapter = chapter, session = session, theory = theory,
|
|
267 |
file = file, url_path = url_path, command = command, start_line = start_line, src_before =
|
|
268 |
src_before, src = src, src_after = src_after, xml = xml, html = html, entity_kname =
|
|
269 |
entity_kname, consts = consts, typs = typs, thms = thms)
|
|
270 |
}
|
|
271 |
|
|
272 |
def read_blocks(
|
|
273 |
db: Solr.Database,
|
|
274 |
q: Solr.Source,
|
|
275 |
fq: List[Solr.Source],
|
|
276 |
cursor: Option[String] = None,
|
|
277 |
max_results: Int = 10
|
|
278 |
): Blocks =
|
|
279 |
db.execute_query(Fields.id, stored_fields, cursor, max_results,
|
|
280 |
{ results =>
|
|
281 |
val next_cursor = results.next_cursor
|
|
282 |
val blocks = results.map(read_block).toList
|
|
283 |
Blocks(results.num_found, blocks, next_cursor)
|
|
284 |
}, q = q, fq = fq, more_chunks = 0)
|
|
285 |
|
|
286 |
def stream_blocks(
|
|
287 |
db: Solr.Database,
|
|
288 |
q: Solr.Source,
|
|
289 |
stream: Iterator[Block] => Unit,
|
|
290 |
cursor: Option[String] = None,
|
|
291 |
): Unit =
|
|
292 |
db.execute_query(Fields.id, stored_fields, cursor, 10000,
|
|
293 |
{ results =>
|
|
294 |
stream(results.map(read_block))
|
|
295 |
}, q = q)
|
|
296 |
|
|
297 |
def update_theory(db: Solr.Database, theory_name: String, blocks: List[Block]): Unit =
|
|
298 |
db.transaction {
|
|
299 |
val delete =
|
|
300 |
read_domain(db, Solr.filter(Fields.theory, Solr.phrase(theory_name))) -- blocks.map(_.id)
|
|
301 |
|
|
302 |
if (delete.nonEmpty) db.execute_batch_delete(delete.toList)
|
|
303 |
|
|
304 |
db.execute_batch_insert(
|
|
305 |
for (block <- blocks) yield { (doc: Solr.Document) =>
|
|
306 |
doc.string(Fields.id) = block.id
|
|
307 |
doc.long(Fields.version) = block.version
|
|
308 |
doc.string(Fields.chapter) = block.chapter
|
|
309 |
doc.string(Fields.session) = block.session
|
|
310 |
doc.string(Fields.session_facet) = block.session
|
|
311 |
doc.string(Fields.theory) = block.theory
|
|
312 |
doc.string(Fields.theory_facet) = block.theory
|
|
313 |
doc.string(Fields.file) = block.file
|
|
314 |
doc.string(Fields.file_type) = block.file_type
|
|
315 |
doc.string(Fields.url_path) = block.url_path.implode
|
|
316 |
doc.string(Fields.command) = block.command
|
|
317 |
doc.int(Fields.start_line) = block.start_line
|
|
318 |
doc.string(Fields.src_before) = block.src_before
|
|
319 |
doc.string(Fields.src) = block.src
|
|
320 |
doc.string(Fields.src_after) = block.src_after
|
|
321 |
doc.bytes(Fields.xml) = YXML.bytes_of_body(block.xml)
|
|
322 |
doc.bytes(Fields.html) = Bytes(block.html)
|
|
323 |
doc.string(Fields.entity_kname) = block.entity_kname
|
|
324 |
doc.string(Fields.consts) = block.consts
|
|
325 |
doc.string(Fields.consts_facet) = block.consts
|
|
326 |
doc.string(Fields.typs) = block.typs
|
|
327 |
doc.string(Fields.typs_facet) = block.typs
|
|
328 |
doc.string(Fields.thms) = block.thms
|
|
329 |
doc.string(Fields.thms_facet) = block.thms
|
|
330 |
doc.string(Fields.names) = block.names
|
|
331 |
doc.string(Fields.kinds) = block.kinds
|
|
332 |
})
|
|
333 |
}
|
|
334 |
|
|
335 |
def read_theory(db: Solr.Database, theory_name: String): List[Block] = {
|
|
336 |
val blocks = new mutable.ListBuffer[Block]
|
|
337 |
stream_blocks(db, Solr.filter(Fields.theory_facet, Solr.phrase(theory_name)), {
|
|
338 |
res => blocks ++= res
|
|
339 |
})
|
|
340 |
blocks.toList
|
|
341 |
}
|
|
342 |
|
|
343 |
def delete_session(db: Solr.Database, session_name: String): Unit =
|
|
344 |
db.transaction {
|
|
345 |
val delete = read_domain(db, Solr.filter(Fields.session, Solr.phrase(session_name)))
|
|
346 |
if (delete.nonEmpty) db.execute_batch_delete(delete.toList)
|
|
347 |
}
|
|
348 |
|
|
349 |
def query_stats(db: Solr.Database, q: Solr.Source, fq: List[Solr.Source]): Stats =
|
|
350 |
db.execute_stats_query(
|
|
351 |
List(Fields.session_facet, Fields.theory_facet, Fields.command, Fields.consts_facet,
|
|
352 |
Fields.typs_facet, Fields.thms_facet, Fields.start_line),
|
|
353 |
{ res =>
|
|
354 |
val results = res.count
|
|
355 |
val sessions = res.count(Fields.session_facet)
|
|
356 |
val theories = res.count(Fields.theory_facet)
|
|
357 |
val commands = res.count(Fields.theory_facet)
|
|
358 |
val consts = res.count(Fields.consts_facet)
|
|
359 |
val typs = res.count(Fields.typs_facet)
|
|
360 |
val thms = res.count(Fields.thms_facet)
|
|
361 |
|
|
362 |
Stats(results, sessions, theories, commands, consts, typs, thms)
|
|
363 |
}, q = q, fq = fq)
|
|
364 |
|
|
365 |
def query_facets(
|
|
366 |
db: Solr.Database,
|
|
367 |
q: Solr.Source,
|
|
368 |
fq: List[Solr.Source],
|
|
369 |
max_terms: Int = 100
|
|
370 |
): Facets =
|
|
371 |
db.execute_facet_query(
|
|
372 |
List(Fields.chapter, Fields.session_facet, Fields.theory_facet, Fields.file_type,
|
|
373 |
Fields.command, Fields.kinds, Fields.consts_facet, Fields.typs_facet, Fields.thms_facet),
|
|
374 |
{ res =>
|
|
375 |
val chapter = res.string(Fields.chapter)
|
|
376 |
val sessions = res.string(Fields.session_facet)
|
|
377 |
val theories = res.string(Fields.theory_facet)
|
|
378 |
val file_types = res.string(Fields.file_type)
|
|
379 |
val commands = res.string(Fields.command)
|
|
380 |
val kinds = res.string(Fields.kinds)
|
|
381 |
val consts = res.string(Fields.consts_facet)
|
|
382 |
val typs = res.string(Fields.typs_facet)
|
|
383 |
val thms = res.string(Fields.thms_facet)
|
|
384 |
|
|
385 |
Facets(chapter, sessions, theories, file_types, commands, kinds, consts, typs, thms)
|
|
386 |
}, q = q, fq = fq, max_terms = max_terms)
|
|
387 |
|
|
388 |
|
|
389 |
/* queries */
|
|
390 |
|
|
391 |
def solr_field(field: Field, select: Boolean = false): Solr.Field =
|
|
392 |
field match {
|
|
393 |
case Field.chapter => Fields.chapter
|
|
394 |
case Field.session if select => Fields.session_facet
|
|
395 |
case Field.session => Fields.session
|
|
396 |
case Field.theory if select => Fields.theory_facet
|
|
397 |
case Field.theory => Fields.theory
|
|
398 |
case Field.file_type => Fields.file_type
|
|
399 |
case Field.command => Fields.command
|
|
400 |
case Field.source => Fields.src
|
|
401 |
case Field.names => Fields.names
|
|
402 |
case Field.consts if select => Fields.consts_facet
|
|
403 |
case Field.consts => Fields.consts
|
|
404 |
case Field.typs if select => Fields.typs_facet
|
|
405 |
case Field.typs => Fields.typs
|
|
406 |
case Field.thms if select => Fields.thms_facet
|
|
407 |
case Field.thms => Fields.thms
|
|
408 |
case Field.kinds => Fields.kinds
|
|
409 |
}
|
|
410 |
|
|
411 |
def solr_query(query: Query): (Solr.Source, List[Solr.Source]) = {
|
|
412 |
def solr_atom(atom: Atom): List[Solr.Source] =
|
|
413 |
atom match {
|
|
414 |
case Atom.Value(s) if s.isEmpty => Nil
|
|
415 |
case Atom.Value(s) if !s.exists(Solr.wildcard_char(_)) => List(Solr.term(s))
|
|
416 |
case Atom.Value(s) =>
|
|
417 |
val terms = s.split("\\s+").toList.filterNot(_.isBlank)
|
|
418 |
if (terms.isEmpty) Nil else terms.map(Solr.wildcard)
|
|
419 |
case Atom.Exact(s) => List(Solr.phrase(s))
|
|
420 |
}
|
|
421 |
|
|
422 |
def solr_atoms(field: Field, atoms: List[Atom]): List[Solr.Source] =
|
|
423 |
for {
|
|
424 |
atom <- atoms
|
|
425 |
source <- solr_atom(atom)
|
|
426 |
} yield Solr.filter(solr_field(field), source)
|
|
427 |
|
|
428 |
def solr_filter(filter: Filter): List[Solr.Source] =
|
|
429 |
filter match {
|
|
430 |
case Field_Filter(field, atoms) => solr_atoms(field, atoms)
|
|
431 |
case any@Any_Filter(atoms) => any.fields.flatMap(solr_atoms(_, atoms))
|
|
432 |
}
|
|
433 |
|
|
434 |
def solr_select(select: Select): Solr.Source = {
|
|
435 |
val field = solr_field(select.field, select = true)
|
|
436 |
Solr.tag(field.name, Solr.filter(field, Solr.OR(select.values.map(Solr.phrase))))
|
|
437 |
}
|
|
438 |
|
|
439 |
val filter = query.filters.map(filter => Solr.OR(solr_filter(filter)))
|
|
440 |
val exclude = query.exclude.flatMap(solr_filter).map(Solr.exclude)
|
|
441 |
val selects = query.selects.map(solr_select)
|
|
442 |
|
|
443 |
(Solr.AND(filter ::: exclude), selects)
|
|
444 |
}
|
|
445 |
}
|
|
446 |
|
|
447 |
def query_block(db: Solr.Database, id: String): Option[Block] = {
|
|
448 |
val q = Solr.filter(Find_Facts.private_data.Fields.id, Solr.phrase(id))
|
|
449 |
Find_Facts.private_data.read_blocks(db, q, Nil).blocks.headOption
|
|
450 |
}
|
|
451 |
|
|
452 |
def query_blocks(db: Solr.Database, query: Query, cursor: Option[String] = None): Blocks = {
|
|
453 |
val (q, fq) = Find_Facts.private_data.solr_query(query)
|
|
454 |
Find_Facts.private_data.read_blocks(db, q, fq, cursor = cursor)
|
|
455 |
}
|
|
456 |
|
|
457 |
def query_stats(db: Solr.Database, query: Query): Stats = {
|
|
458 |
val (q, fq) = Find_Facts.private_data.solr_query(query)
|
|
459 |
Find_Facts.private_data.query_stats(db, q, fq)
|
|
460 |
}
|
|
461 |
|
|
462 |
def query_facet(db: Solr.Database, query: Query): Facets = {
|
|
463 |
val (q, fq) = Find_Facts.private_data.solr_query(query)
|
|
464 |
Find_Facts.private_data.query_facets(db, q, fq)
|
|
465 |
}
|
|
466 |
|
|
467 |
|
|
468 |
/** indexing **/
|
|
469 |
|
|
470 |
def make_thy_blocks(
|
|
471 |
options: Options,
|
|
472 |
session: Session,
|
|
473 |
browser_info_context: Browser_Info.Context,
|
|
474 |
document_info: Document_Info,
|
|
475 |
theory_context: Export.Theory_Context,
|
|
476 |
snapshot: Document.Snapshot,
|
|
477 |
chapter: String
|
|
478 |
): List[Block] = {
|
|
479 |
val theory = theory_context.theory
|
|
480 |
val entities = Export_Theory.read_theory(theory_context).entity_iterator.toList
|
|
481 |
val session_name = theory_context.session_context.session_name
|
|
482 |
|
|
483 |
val theory_info =
|
|
484 |
document_info.theory_by_name(session_name, theory).getOrElse(
|
|
485 |
error("No info for theory " + theory))
|
|
486 |
val thy_dir = browser_info_context.theory_dir(theory_info)
|
|
487 |
|
|
488 |
def make_node_blocks(
|
|
489 |
snapshot: Document.Snapshot,
|
|
490 |
command_ranges: List[(String, Text.Range)]
|
|
491 |
): List[Block] = {
|
|
492 |
val version = snapshot.version.id
|
|
493 |
val file = Path.explode(snapshot.node_name.node).squash.implode
|
|
494 |
val url_path = thy_dir + browser_info_context.smart_html(theory_info, snapshot.node_name.node)
|
|
495 |
|
|
496 |
val elements =
|
|
497 |
Browser_Info.Elements(html = Browser_Info.default_elements.html - Markup.ENTITY)
|
|
498 |
val node_context = Browser_Info.Node_Context.empty
|
|
499 |
|
|
500 |
val content = XML.content(snapshot.xml_markup(elements = Markup.Elements.empty))
|
|
501 |
def get_content(range: Text.Range): String =
|
|
502 |
Symbol.decode(Line.normalize(range.substring(content)))
|
|
503 |
|
|
504 |
val document = Line.Document(content.replace('\r', '\u001a'))
|
|
505 |
val num_lines = document.lines.length
|
|
506 |
def content_range(start: Line.Position, stop: Line.Position): Text.Range =
|
|
507 |
Text.Range(document.offset(start).get, document.offset(stop).get)
|
|
508 |
|
|
509 |
val index = Symbol.Index(content)
|
|
510 |
val node_entities =
|
|
511 |
TreeMap.from(entities
|
|
512 |
.filter(entity => entity.file == snapshot.node_name.node)
|
|
513 |
.groupBy(entity => index.decode(entity.range).start))
|
|
514 |
|
|
515 |
val rendering = new Rendering(snapshot, options, session)
|
|
516 |
val comment_ranges = rendering.comments(Text.Range.full).map(markup => ("", markup.range))
|
|
517 |
|
|
518 |
for ((command, range) <- command_ranges ::: comment_ranges) yield {
|
|
519 |
val line_range = document.range(range)
|
|
520 |
val start_line = line_range.start.line1
|
|
521 |
|
|
522 |
val id = file + "|" + range.start + ".." + range.stop
|
|
523 |
|
|
524 |
val src_before = get_content(
|
|
525 |
content_range(Line.Position((line_range.start.line - 5).max(0)), line_range.start))
|
|
526 |
val src = get_content(range)
|
|
527 |
val src_after = get_content(
|
|
528 |
content_range(line_range.stop, Line.Position((line_range.stop.line + 5).min(num_lines))))
|
|
529 |
|
|
530 |
val xml = snapshot.xml_markup(range, elements = elements.html)
|
|
531 |
val html =
|
|
532 |
HTML.output(node_context.make_html(elements, xml), hidden = true, structural = false)
|
|
533 |
|
|
534 |
val entities = node_entities.range(range.start, range.stop).values.toList.flatten.distinct
|
|
535 |
|
|
536 |
def get_entities(kind: String): List[String] =
|
|
537 |
for {
|
|
538 |
entity <- entities
|
|
539 |
if entity.export_kind == kind
|
|
540 |
if range.contains(index.decode(entity.range))
|
|
541 |
} yield entity.name
|
|
542 |
|
|
543 |
val entity_kname = entities.sortBy(_.name.length).headOption.map(_.kname)
|
|
544 |
|
|
545 |
val typs = get_entities(Export_Theory.Kind.TYPE)
|
|
546 |
val consts = get_entities(Export_Theory.Kind.CONST)
|
|
547 |
val thms = get_entities(Export_Theory.Kind.THM)
|
|
548 |
|
|
549 |
Block(id = id, version = version, chapter = chapter, session = session_name, theory =
|
|
550 |
theory, file = file, url_path = url_path, command = command, start_line = start_line,
|
|
551 |
src_before = src_before, src = src, src_after = src_after, xml = xml, html = html,
|
|
552 |
entity_kname = entity_kname, consts = consts, typs = typs, thms = thms)
|
|
553 |
}
|
|
554 |
}
|
|
555 |
|
|
556 |
def expand_block(block: Thy_Blocks.Block): List[Thy_Blocks.Block] =
|
|
557 |
block match {
|
|
558 |
case Thy_Blocks.Thy(inner) => inner.flatMap(expand_block)
|
|
559 |
case e@Thy_Blocks.Decl(inner) =>
|
|
560 |
val inner1 = inner.flatMap(expand_block)
|
|
561 |
if (inner.length > 1) e :: inner1 else List(e)
|
|
562 |
case _ => List(block)
|
|
563 |
}
|
|
564 |
|
|
565 |
val thy_command_ranges =
|
|
566 |
for (block <- Thy_Blocks.read_blocks(snapshot).flatMap(expand_block))
|
|
567 |
yield (block.command, block.range)
|
|
568 |
|
|
569 |
make_node_blocks(snapshot, thy_command_ranges) :::
|
|
570 |
(for {
|
|
571 |
blob_name <- snapshot.node_files.tail
|
|
572 |
snapshot1 = snapshot.switch(blob_name)
|
|
573 |
if snapshot1.node.source_wellformed
|
|
574 |
range = Text.Range.length(snapshot1.node.source)
|
|
575 |
block <- make_node_blocks(snapshot1, List(("", range)))
|
|
576 |
} yield block)
|
|
577 |
}
|
|
578 |
|
|
579 |
def find_facts_index(
|
|
580 |
options: Options,
|
|
581 |
sessions: List[String],
|
|
582 |
dirs: List[Path] = Nil,
|
|
583 |
clean: Boolean = false,
|
|
584 |
progress: Progress = new Progress
|
|
585 |
): Unit = {
|
|
586 |
val store = Store(options)
|
|
587 |
val database = options.string("find_facts_database_name")
|
|
588 |
val session = Session(options, Resources.bootstrap)
|
|
589 |
|
|
590 |
val selection = Sessions.Selection(sessions = sessions)
|
|
591 |
val session_structure = Sessions.load_structure(options, dirs = dirs).selection(selection)
|
|
592 |
val deps = Sessions.Deps.load(session_structure)
|
|
593 |
val browser_info_context = Browser_Info.context(session_structure)
|
|
594 |
|
|
595 |
if (sessions.isEmpty) progress.echo("Nothing to index")
|
|
596 |
else {
|
|
597 |
val stats =
|
|
598 |
using(Solr.init_database(database, Find_Facts.private_data, clean = clean)) { db =>
|
|
599 |
using(Export.open_database_context(store)) { database_context =>
|
|
600 |
val document_info = Document_Info.read(database_context, deps, sessions)
|
|
601 |
|
|
602 |
def index_session(session_name: String): Unit = {
|
|
603 |
using(database_context.open_session0(session_name)) { session_context =>
|
|
604 |
val info = session_structure(session_name)
|
|
605 |
progress.echo("Session " + info.chapter + "/" + session_name + " ...")
|
|
606 |
|
|
607 |
Find_Facts.private_data.delete_session(db, session_name)
|
|
608 |
deps(session_name).proper_session_theories.foreach { name =>
|
|
609 |
val theory_context = session_context.theory(name.theory)
|
|
610 |
Build.read_theory(theory_context) match {
|
|
611 |
case None => progress.echo_warning("No snapshot for theory " + name.theory)
|
|
612 |
case Some(snapshot) =>
|
|
613 |
progress.echo("Theory " + name.theory + " ...")
|
|
614 |
val blocks =
|
|
615 |
make_thy_blocks(options, session, browser_info_context, document_info,
|
|
616 |
theory_context, snapshot, info.chapter)
|
|
617 |
Find_Facts.private_data.update_theory(db, theory_context.theory, blocks)
|
|
618 |
}
|
|
619 |
}
|
|
620 |
}
|
|
621 |
}
|
|
622 |
|
|
623 |
Par_List.map(index_session, sessions)
|
|
624 |
}
|
|
625 |
|
|
626 |
val query = Query(Field_Filter(Field.session, sessions.map(Atom.Exact(_))))
|
|
627 |
Find_Facts.query_stats(db, query)
|
|
628 |
}
|
|
629 |
|
|
630 |
progress.echo("Indexed " + stats.results + " blocks with " +
|
|
631 |
stats.consts + " consts, " + stats.typs + " typs, " + stats.thms + " thms")
|
|
632 |
}
|
|
633 |
}
|
|
634 |
|
|
635 |
|
|
636 |
/* Isabelle tool wrapper */
|
|
637 |
|
81770
|
638 |
val isabelle_tool1 = Isabelle_Tool("find_facts_index", "index sessions for find_facts",
|
81764
|
639 |
Scala_Project.here,
|
|
640 |
{ args =>
|
|
641 |
var clean = false
|
|
642 |
val dirs = new mutable.ListBuffer[Path]
|
|
643 |
var options = Options.init()
|
|
644 |
|
|
645 |
val getopts = Getopts("""
|
|
646 |
Usage: isabelle find_facts_index [OPTIONS] [SESSIONS ...]
|
|
647 |
|
|
648 |
Options are:
|
|
649 |
-c clean previous index
|
|
650 |
-d DIR include session directory
|
|
651 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME)
|
|
652 |
|
|
653 |
Index sessions for find_facts.
|
|
654 |
""",
|
|
655 |
"c" -> (_ => clean = true),
|
|
656 |
"d:" -> (arg => dirs += Path.explode(arg)),
|
|
657 |
"o:" -> (arg => options = options + arg))
|
|
658 |
|
|
659 |
val sessions = getopts(args)
|
|
660 |
|
|
661 |
val progress = new Console_Progress()
|
|
662 |
|
|
663 |
find_facts_index(options, sessions, dirs = dirs.toList, clean = clean, progress = progress)
|
|
664 |
})
|
|
665 |
|
|
666 |
|
|
667 |
/** index components **/
|
|
668 |
|
|
669 |
def find_facts_index_component(
|
|
670 |
options: Options,
|
|
671 |
target_dir: Path = Path.current,
|
|
672 |
progress: Progress = new Progress
|
|
673 |
): Unit = {
|
|
674 |
val database = options.string("find_facts_database_name")
|
|
675 |
|
|
676 |
val component = "find_facts_index-" + database
|
|
677 |
val component_dir =
|
|
678 |
Components.Directory(target_dir + Path.basic(component)).create(progress = progress)
|
|
679 |
|
|
680 |
Isabelle_System.copy_dir(Solr.database_dir(database), component_dir.path)
|
|
681 |
component_dir.write_settings("SOLR_COMPONENTS=\"$SOLR_COMPONENTS:$COMPONENT/" + database + "\"")
|
|
682 |
}
|
|
683 |
|
|
684 |
|
|
685 |
/* Isabelle tool wrapper */
|
|
686 |
|
81770
|
687 |
val isabelle_tool2 = Isabelle_Tool("find_facts_index_component",
|
81764
|
688 |
"build component from find_facts index", Scala_Project.here,
|
|
689 |
{ args =>
|
|
690 |
var options = Options.init()
|
|
691 |
var target_dir = Path.current
|
|
692 |
|
|
693 |
val getopts = Getopts("""
|
|
694 |
Usage: isabelle find_facts_index_component
|
|
695 |
|
|
696 |
Options are:
|
|
697 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME)
|
|
698 |
-D DIR target directory (default ".")
|
|
699 |
|
|
700 |
Build component from finalized find_facts index with given name.
|
|
701 |
""",
|
|
702 |
"o:" -> (arg => options = options + arg),
|
|
703 |
"D:" -> (arg => target_dir = Path.explode(arg)))
|
|
704 |
|
|
705 |
val more_args = getopts(args)
|
|
706 |
if (more_args.nonEmpty) getopts.usage()
|
|
707 |
|
|
708 |
find_facts_index_component(options, target_dir = target_dir)
|
|
709 |
})
|
|
710 |
|
|
711 |
|
|
712 |
/** querying **/
|
|
713 |
|
|
714 |
/* requests and parsing */
|
|
715 |
|
|
716 |
case class Query_Blocks(query: Query, cursor: String)
|
|
717 |
|
|
718 |
object Parse {
|
|
719 |
def atom(json: JSON.T): Option[Atom] =
|
|
720 |
JSON.string(json, "value").map(Atom.Value(_)) orElse
|
|
721 |
JSON.string(json, "exact").map(Atom.Exact(_))
|
|
722 |
|
|
723 |
def field(name: String): Option[Field] = Field.values.find(_.toString == name)
|
|
724 |
|
|
725 |
def filter(json: JSON.T): Option[Filter] =
|
|
726 |
for {
|
|
727 |
atoms <- JSON.list(json, "either", atom)
|
|
728 |
filter <-
|
|
729 |
JSON.string(json, "field") match {
|
|
730 |
case None => Some(Any_Filter(atoms))
|
|
731 |
case Some(name) => for (field <- field(name)) yield Field_Filter(field, atoms)
|
|
732 |
}
|
|
733 |
} yield filter
|
|
734 |
|
|
735 |
def select(json: JSON.T): Option[Select] =
|
|
736 |
for {
|
|
737 |
name <- JSON.string(json, "field")
|
|
738 |
field <- field(name)
|
|
739 |
values <- JSON.strings(json, "values")
|
|
740 |
} yield Select(field, values)
|
|
741 |
|
|
742 |
def query(json: JSON.T): Option[Query] =
|
|
743 |
for {
|
|
744 |
filters <- JSON.list(json, "filters", filter)
|
|
745 |
exclude <- JSON.list(json, "exclude", filter)
|
|
746 |
selects <- JSON.list(json, "selects", select)
|
|
747 |
} yield Query(filters, exclude, selects)
|
|
748 |
|
|
749 |
def query_blocks(json: JSON.T): Option[Query_Blocks] =
|
|
750 |
for {
|
|
751 |
query <- JSON.value(json, "query", query)
|
|
752 |
cursor <- JSON.string(json, "cursor")
|
|
753 |
} yield Query_Blocks(query, cursor)
|
|
754 |
|
|
755 |
def query_block(json: JSON.T): Option[String] = for (id <- JSON.string(json, "id")) yield id
|
|
756 |
}
|
|
757 |
|
|
758 |
|
|
759 |
/* responses and encoding */
|
|
760 |
|
|
761 |
case class Result(blocks: Blocks, facets: Facets)
|
|
762 |
|
|
763 |
class Encode(options: Options) {
|
|
764 |
val library_base_url = Url(options.string("browser_info_url_library"))
|
|
765 |
val afp_base_url = Url(options.string("browser_info_url_afp"))
|
|
766 |
|
|
767 |
def url(block: Block): Url = {
|
|
768 |
val base_url = if (block.chapter == AFP.chapter) afp_base_url else library_base_url
|
|
769 |
base_url.resolve(block.url_path.implode)
|
|
770 |
}
|
|
771 |
|
|
772 |
def block(block: Block): JSON.T =
|
|
773 |
JSON.Object(
|
|
774 |
"id" -> block.id,
|
|
775 |
"chapter" -> block.chapter,
|
|
776 |
"session" -> block.session,
|
|
777 |
"theory" -> block.theory,
|
|
778 |
"file" -> block.file,
|
|
779 |
"file_name" -> block.file_name,
|
|
780 |
"url" -> url(block).toString,
|
|
781 |
"command" -> block.command,
|
|
782 |
"start_line" -> block.start_line,
|
|
783 |
"src_before" -> block.src_before,
|
|
784 |
"src_after" -> block.src_after,
|
|
785 |
"html" -> block.html,
|
|
786 |
"entity_kname" -> block.entity_kname.orNull)
|
|
787 |
|
|
788 |
def blocks(blocks: Blocks): JSON.T =
|
|
789 |
JSON.Object(
|
|
790 |
"num_found" -> blocks.num_found,
|
|
791 |
"blocks" -> blocks.blocks.map(block),
|
|
792 |
"cursor" -> blocks.cursor)
|
|
793 |
|
|
794 |
def facets(facet: Facets): JSON.T =
|
|
795 |
JSON.Object(
|
|
796 |
"chapter" -> facet.chapter,
|
|
797 |
"session" -> facet.session,
|
|
798 |
"file_type" -> facet.file_type,
|
|
799 |
"theory" -> facet.theory,
|
|
800 |
"command" -> facet.command,
|
|
801 |
"kinds" -> facet.kinds,
|
|
802 |
"consts" -> facet.consts,
|
|
803 |
"typs" -> facet.typs,
|
|
804 |
"thms" -> facet.thms)
|
|
805 |
|
|
806 |
def result(result: Result): JSON.T =
|
|
807 |
JSON.Object(
|
|
808 |
"blocks" -> blocks(result.blocks),
|
|
809 |
"facets" -> facets(result.facets))
|
|
810 |
}
|
|
811 |
|
|
812 |
|
|
813 |
/* find facts */
|
|
814 |
|
|
815 |
abstract class REST_Service(path: Path, progress: Progress, method: String = "POST")
|
|
816 |
extends HTTP.Service(path.implode, method = method) {
|
|
817 |
def handle(body: JSON.T): Option[JSON.T]
|
|
818 |
|
|
819 |
def apply(request: HTTP.Request): Option[HTTP.Response] =
|
|
820 |
try {
|
|
821 |
for {
|
|
822 |
json <-
|
|
823 |
Exn.capture(JSON.parse(request.input.text)) match {
|
|
824 |
case Exn.Res(json) => Some(json)
|
|
825 |
case _ =>
|
|
826 |
progress.echo("Could not parse: " + quote(request.input.text), verbose = true)
|
|
827 |
None
|
|
828 |
}
|
|
829 |
res <-
|
|
830 |
handle(json) match {
|
|
831 |
case Some(res) => Some(res)
|
|
832 |
case None =>
|
|
833 |
progress.echo("Invalid request: " + JSON.Format(json), verbose = true)
|
|
834 |
None
|
|
835 |
}
|
|
836 |
} yield HTTP.Response(Bytes(JSON.Format(res)), content_type = "application/json")
|
|
837 |
}
|
|
838 |
catch { case exn: Throwable =>
|
|
839 |
val uuid = UUID.random()
|
|
840 |
progress.echo_error_message("Server error <" + uuid + ">: " + exn)
|
|
841 |
Some(HTTP.Response.text("internal server error: " + uuid))
|
|
842 |
}
|
|
843 |
}
|
|
844 |
|
|
845 |
def find_facts(
|
|
846 |
options: Options,
|
|
847 |
port: Int,
|
|
848 |
devel: Boolean = false,
|
|
849 |
progress: Progress = new Progress
|
|
850 |
): Unit = {
|
|
851 |
val database = options.string("find_facts_database_name")
|
|
852 |
val encode = new Encode(options)
|
|
853 |
val logo = Bytes.read(Path.explode("$FIND_FACTS_HOME/web/favicon.ico"))
|
|
854 |
|
|
855 |
val isabelle_style = HTML.fonts_css("/fonts/" + _) + "\n\n" + File.read(HTML.isabelle_css)
|
|
856 |
|
|
857 |
val project = Elm.Project("Find_Facts", Path.explode("$FIND_FACTS_HOME/web"), head = List(
|
|
858 |
HTML.style("html,body {width: 100%, height: 100%}"),
|
|
859 |
Web_App.More_HTML.icon("data:image/x-icon;base64," + logo.encode_base64.text),
|
|
860 |
HTML.style_file("isabelle.css"),
|
|
861 |
HTML.style_file("https://fonts.googleapis.com/css?family=Roboto:300,400,500|Material+Icons"),
|
|
862 |
HTML.style_file(
|
|
863 |
"https://unpkg.com/material-components-web-elm@9.1.0/dist/material-components-web-elm.min.css"),
|
|
864 |
HTML.script_file(
|
|
865 |
"https://unpkg.com/material-components-web-elm@9.1.0/dist/material-components-web-elm.min.js")))
|
|
866 |
|
|
867 |
val frontend = project.build_html(progress)
|
|
868 |
|
|
869 |
using(Solr.open_database(database)) { db =>
|
|
870 |
val stats = Find_Facts.query_stats(db, Query(Nil))
|
|
871 |
progress.echo("Started find facts with " + stats.results + " blocks, " +
|
|
872 |
stats.consts + " consts, " + stats.typs + " typs, " + stats.thms + " thms")
|
|
873 |
|
|
874 |
val server =
|
|
875 |
HTTP.server(port, name = "", services = List(
|
|
876 |
HTTP.Fonts_Service,
|
|
877 |
new HTTP.Service("isabelle.css") {
|
|
878 |
def apply(request: HTTP.Request): Option[HTTP.Response] =
|
|
879 |
Some(HTTP.Response(Bytes(isabelle_style), "text/css"))
|
|
880 |
},
|
|
881 |
new HTTP.Service("app") {
|
|
882 |
def apply(request: HTTP.Request): Option[HTTP.Response] =
|
|
883 |
Some(HTTP.Response.html(if (devel) project.build_html(progress) else frontend))
|
|
884 |
},
|
|
885 |
new REST_Service(Path.explode("api/block"), progress) {
|
|
886 |
def handle(body: JSON.T): Option[JSON.T] =
|
|
887 |
for {
|
|
888 |
request <- Parse.query_block(body)
|
|
889 |
block <- query_block(db, request)
|
|
890 |
} yield encode.block(block)
|
|
891 |
},
|
|
892 |
new REST_Service(Path.explode("api/blocks"), progress) {
|
|
893 |
def handle(body: JSON.T): Option[JSON.T] =
|
|
894 |
for (request <- Parse.query_blocks(body))
|
|
895 |
yield encode.blocks(query_blocks(db, request.query, Some(request.cursor)))
|
|
896 |
},
|
|
897 |
new REST_Service(Path.explode("api/query"), progress) {
|
|
898 |
def handle(body: JSON.T): Option[JSON.T] =
|
|
899 |
for (query <- Parse.query(body)) yield {
|
|
900 |
val facet = query_facet(db, query)
|
|
901 |
val blocks = query_blocks(db, query)
|
|
902 |
encode.result(Result(blocks, facet))
|
|
903 |
}
|
|
904 |
}))
|
|
905 |
|
|
906 |
server.start()
|
|
907 |
progress.echo("Server started on port " + server.http_server.getAddress.getPort)
|
|
908 |
|
|
909 |
@tailrec
|
|
910 |
def loop(): Unit = {
|
|
911 |
Thread.sleep(Long.MaxValue)
|
|
912 |
loop()
|
|
913 |
}
|
|
914 |
|
|
915 |
Isabelle_Thread.interrupt_handler(_ => server.stop()) { loop() }
|
|
916 |
}
|
|
917 |
}
|
|
918 |
|
|
919 |
|
|
920 |
/* Isabelle tool wrapper */
|
|
921 |
|
81770
|
922 |
val isabelle_tool3 = Isabelle_Tool("find_facts", "run find_facts server", Scala_Project.here,
|
81764
|
923 |
{ args =>
|
|
924 |
var devel = false
|
|
925 |
var options = Options.init()
|
|
926 |
var port = 8080
|
|
927 |
var verbose = false
|
|
928 |
|
|
929 |
val getopts = Getopts("""
|
|
930 |
Usage: isabelle find_facts [OPTIONS]
|
|
931 |
|
|
932 |
Options are:
|
|
933 |
-d devel mode
|
|
934 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME)
|
|
935 |
-p PORT explicit web server port
|
|
936 |
-v verbose server
|
|
937 |
|
|
938 |
Run the find_facts web service.
|
|
939 |
""",
|
|
940 |
"d" -> (_ => devel = true),
|
|
941 |
"o:" -> (arg => options = options + arg),
|
|
942 |
"p:" -> (arg => port = Value.Int.parse(arg)),
|
|
943 |
"v" -> (_ => verbose = true))
|
|
944 |
|
|
945 |
val more_args = getopts(args)
|
|
946 |
if (more_args.nonEmpty) getopts.usage()
|
|
947 |
|
|
948 |
val progress = new Console_Progress(verbose = verbose)
|
|
949 |
|
|
950 |
find_facts(options, port, devel = devel, progress = progress)
|
|
951 |
})
|
|
952 |
}
|