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