My personal data management layer
at main 86 lines 3.5 kB view raw
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6(** Generate descriptive text for Bushel entries *) 7 8(** Format a date as "Month Year" *) 9let format_date (year, month, _day) = 10 Printf.sprintf "%s %d" (Bushel_types.month_name month) year 11 12(** Generate a descriptive sentence for a paper *) 13let paper_description (p : Bushel_paper.t) ~date_str = 14 let venue = match String.lowercase_ascii (Bushel_paper.bibtype p) with 15 | "inproceedings" -> Bushel_paper.booktitle p 16 | "article" -> Bushel_paper.journal p 17 | "book" -> 18 let pub = Bushel_paper.publisher p in 19 if pub = "" then "Book" else "Book by " ^ pub 20 | "techreport" -> 21 let inst = Bushel_paper.institution p in 22 if inst = "" then "Technical report" else "Technical report at " ^ inst 23 | "misc" -> 24 let pub = Bushel_paper.publisher p in 25 if pub = "" then "Working paper" else "Working paper at " ^ pub 26 | _ -> "Publication" 27 in 28 Printf.sprintf "Paper in %s (%s)" venue date_str 29 30(** Generate a descriptive sentence for a note *) 31let note_description (n : Bushel_note.t) ~date_str ~lookup_fn = 32 match Bushel_note.slug_ent n with 33 | Some slug_ent -> 34 (match lookup_fn slug_ent with 35 | Some related_title -> 36 Printf.sprintf "Note about %s (%s)" related_title date_str 37 | None -> Printf.sprintf "Research note (%s)" date_str) 38 | None -> Printf.sprintf "Research note (%s)" date_str 39 40(** Generate a descriptive sentence for an idea *) 41let idea_description (i : Bushel_idea.t) ~date_str = 42 let status_str = String.lowercase_ascii (Bushel_idea.status_to_string (Bushel_idea.status i)) in 43 let level_str = Bushel_idea.level_to_string (Bushel_idea.level i) in 44 Printf.sprintf "Research idea (%s, %s level, %s)" status_str level_str date_str 45 46(** Generate a descriptive sentence for a video *) 47let video_description (v : Bushel_video.t) ~date_str ~lookup_fn = 48 let video_type = if Bushel_video.talk v then "Talk video" else "Video" in 49 let context = match Bushel_video.paper v with 50 | Some paper_slug -> 51 (match lookup_fn paper_slug with 52 | Some title -> Printf.sprintf " about %s" title 53 | None -> "") 54 | None -> 55 (match Bushel_video.project v with 56 | Some project_slug -> 57 (match lookup_fn project_slug with 58 | Some title -> Printf.sprintf " about %s" title 59 | None -> "") 60 | None -> "") 61 in 62 Printf.sprintf "%s%s (%s)" video_type context date_str 63 64(** Generate a descriptive sentence for a project *) 65let project_description (pr : Bushel_project.t) = 66 let end_str = match Bushel_project.finish pr with 67 | Some year -> string_of_int year 68 | None -> "present" 69 in 70 Printf.sprintf "Project (%d–%s)" (Bushel_project.start pr) end_str 71 72(** Generate description for any entry type *) 73let entry_description entries entry = 74 let lookup_fn slug = 75 match Bushel_entry.lookup entries slug with 76 | Some e -> Some (Bushel_entry.title e) 77 | None -> None 78 in 79 let date = Bushel_entry.date entry in 80 let date_str = format_date date in 81 match entry with 82 | `Paper p -> paper_description p ~date_str 83 | `Note n -> note_description n ~date_str ~lookup_fn 84 | `Idea i -> idea_description i ~date_str 85 | `Video v -> video_description v ~date_str ~lookup_fn 86 | `Project p -> project_description p