Class: Suma::NoteProcessor
- Inherits:
-
Object
- Object
- Suma::NoteProcessor
- Defined in:
- lib/suma/note_processor.rb
Overview
Cleans raw EXPRESS entity remarks into a list of
Glossarist::V3::DetailedDefinition notes.
Pipeline:
1. trim to first sentence / first complete list
2. convert express xrefs to URN mentions
3. drop redundant "X is a type of {{...}}" opening notes
4. drop notes containing image references or <<...>> blocks
5. drop notes that duplicate the first definition
Pure: no I/O, no schema knowledge. The schema domain label and
URN composition are injected via xref_to_mention so this module
stays independent of Suma::Urn and the surrounding extractor.
Constant Summary collapse
- REDUNDANT_NOTE_REGEX =
%r{ ^An? # Starts with "A" or "An" \s.*?\sis\sa\stype\sof # Text followed by "is a type of" (\sa|\san)? # Optional " a" or " an" \s\{\{[^\}]*\}\} # Text in double curly braces \s*?\.?$ # Optional whitespace and period at the end }x- IMAGE_REF_SUBSTRING =
"image::"- DOUBLE_ANGLE_PATTERN =
/<<(.*?){1,999}>>/- SEE_TAIL_PATTERN =
/\s+\(see(.*?){1,999}\)/- XREF_WITH_DISPLAY =
/<<express:([\w.]+),([\w. ][\w. ]*)>>/- XREF_WITHOUT_DISPLAY =
/<<express:([\w.]+)>>/- INLINE_COMMENT_PATTERN =
/\n\/\/.*?\n/- BULLET_LIST_PATTERN =
/^\s*[*\-+]\s+/- NUMBERED_LIST_PATTERN =
/^\s*\d+\.\s+/- CONTINUATION_PLUS =
/^\+\s*$/- CONTINUATION_DASHES =
/^--\s*$/- INDENTED_PATTERN =
/^\s{2,}/- SENTENCE_BREAK_NEWLINE =
/\.\n/- SENTENCE_BREAK_SPACE =
/\. /
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
-
#remarks ⇒ Object
readonly
Returns the value of attribute remarks.
-
#xref_to_mention ⇒ Object
readonly
Returns the value of attribute xref_to_mention.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(remarks, definitions:, xref_to_mention:) ⇒ NoteProcessor
constructor
A new instance of NoteProcessor.
Constructor Details
#initialize(remarks, definitions:, xref_to_mention:) ⇒ NoteProcessor
Returns a new instance of NoteProcessor.
45 46 47 48 49 |
# File 'lib/suma/note_processor.rb', line 45 def initialize(remarks, definitions:, xref_to_mention:) @remarks = remarks @definitions = definitions @xref_to_mention = xref_to_mention end |
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
43 44 45 |
# File 'lib/suma/note_processor.rb', line 43 def definitions @definitions end |
#remarks ⇒ Object (readonly)
Returns the value of attribute remarks.
43 44 45 |
# File 'lib/suma/note_processor.rb', line 43 def remarks @remarks end |
#xref_to_mention ⇒ Object (readonly)
Returns the value of attribute xref_to_mention.
43 44 45 |
# File 'lib/suma/note_processor.rb', line 43 def xref_to_mention @xref_to_mention end |
Class Method Details
.call(remarks, definitions:, xref_to_mention:) ⇒ Object
51 52 53 |
# File 'lib/suma/note_processor.rb', line 51 def self.call(remarks, definitions:, xref_to_mention:) new(remarks, definitions: definitions, xref_to_mention: xref_to_mention).call end |
Instance Method Details
#call ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/suma/note_processor.rb', line 55 def call notes = build_initial_notes notes = only_keep_first_sentence(notes) notes = remove_see_content(notes) notes = remove_redundant_note(notes) notes = remove_invalid_references(notes) compare_with_definitions(notes, definitions) end |