14.5.7. crate_anon.nlp_manager.build_medex_itself

crate_anon/nlp_manager/build_medex_itself.py


Copyright (C) 2015, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

This file is part of CRATE.

CRATE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CRATE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CRATE. If not, see <https://www.gnu.org/licenses/>.


Script to compile (and modify slightly) Java source for MedEx-UIMA.

crate_anon.nlp_manager.build_medex_itself.add_lines_after_trigger(filename: str, trigger: str, start_marker: str, end_marker: str, lines: List[str]) None[source]

Adds lines to a file, after a triggering line.

Parameters
  • filename – name of file to modify

  • trigger – line that begins the section of interest; we don’t start paying attention until this is encountered

  • start_marker – see below

  • end_marker – see below

  • lines – lines to insert

Immediately after we’ve encountered trigger, we insert start_marker, then lines, then end_marker.

If the file already has such a block, we chop out the old block before inserting the new.

Elements of lines should not have their own \n characters.

crate_anon.nlp_manager.build_medex_itself.add_lines_if_not_in(filename: str, lines: List[str]) None[source]

Adds lines to a file, if they’re not already there.

Parameters
  • filename – name of file to modify

  • lines – lines to insert

Elements of lines should not have their own \n characters.

crate_anon.nlp_manager.build_medex_itself.frequency_rules_line(frequency: str, timex: str, dots_optional: bool) str[source]

Creates a line for MedEx’s frequency_rules file.

Parameters
  • frequency – the string representing a drug frequency, e.g. “b.d.”

  • timex – a TIMEX version of this frequency

  • dots_optional – if frequency contains full stops, are they optional?

Returns

a line to go into the frequency_rules file

crate_anon.nlp_manager.build_medex_itself.lex_freq(x: str) str[source]

For MedEx’s lexicon.cfg: creates a frequency line.

crate_anon.nlp_manager.build_medex_itself.lex_route(x: str) str[source]

For MedEx’s lexicon.cfg: creates a route line.

crate_anon.nlp_manager.build_medex_itself.main() None[source]

Command-line processor. See command-line help.

crate_anon.nlp_manager.build_medex_itself.replace_in_file(filename: str, changes: List[Tuple[str, str]], count: int = - 1, encoding: str = 'utf8', backup_suffix: str = '~') None[source]

Replaces content in a file.

Parameters
  • filename – name of file to modify

  • changes – list of old, new tuples; we will replace old by new in each case

  • count – up to how many times should we perform the replacement? See str.replace().

  • encoding – character encoding to be used

  • backup_suffix – we’ll create a backup file; what should we append to the filename to give the name of the backup file?

crate_anon.nlp_manager.build_medex_itself.semantic_rule_engine_line(frequency: str, dots_optional: bool = True) str[source]

For MedEx: create a semantic rule engine line (a line of Java to be inserted).

Parameters
  • frequency – string representing the frequency, e.g. “b.d.”

  • dots_optional – if frequency contains full stops, are they optional?

Returns

a line of Java code

crate_anon.nlp_manager.build_medex_itself.terminate(x: str) str[source]

Terminates its input with a newline.