source: code/trunk/lib/topic_set.ml@ 2

Last change on this file since 2 was 2, checked in by fox, 3 years ago

Samhain 21

Converter

  • type selection
  • subdir conversion
  • htm extension

Gemini

  • index.gmi
  • topics and latest
  • gmi.atom feed

Add pull (http(s)) operation

  • peers.pub.conf and peers.priv.conf

HTML5 format & fixes by Novaburst
Phony target (thanks Gergely)

May

Basic unit renamed from Note to Text.
New modular text-parser, internal to Logarion, for generic notation parsing. The default input format is now a much plainer text.
Logarion created texts have part of the UUID in filename.
Logarion's index re-written in Messagepack format. Removed indices command. They are generated during convert.

File size: 1.2 KB
Line 
1let of_string x = Re.Str.(split (regexp " *> *")) (String.trim x)
2
3let topic x =
4 let path = of_string x in
5 try List.nth path (List.length path - 1) with _ -> ""
6
7module Map = Map.Make(String)
8
9let edges x map = try Map.find x map with Not_found -> (String_set.empty, String_set.empty)
10
11let edges_with_context context (contexts, subtopics) = (String_set.add context contexts, subtopics)
12let edges_with_subtopic subtopic (contexts, subtopics) = (contexts, String_set.add subtopic subtopics)
13
14let rec list_to_map map = function
15 | [] -> map
16 | [topic] ->
17 let edges = edges topic map in
18 Map.add topic edges map
19 | context :: topic :: tail ->
20 let context_edges = edges context map in
21 let topic_edges = edges topic map in
22 let map =
23 map
24 |> Map.add context (edges_with_subtopic topic context_edges)
25 |> Map.add topic (edges_with_context context topic_edges)
26 in
27 list_to_map map (topic :: tail)
28
29let to_map map set =
30 List.fold_left (fun acc elt -> list_to_map acc (of_string elt)) map @@ String_set.elements set
31
32let roots map =
33 let root_keys acc (key, (contexts, _topics)) = if String_set.is_empty contexts then key :: acc else acc in
34 List.fold_left root_keys [] @@ Map.bindings map
35
Note: See TracBrowser for help on using the repository browser.