configuration/strings/reference.strings.ts
configuration/strings/reference.strings.ts is a file in Bane's Lab Site. 124 lines of code and 27 definitions.
import {
AXIS_LABEL,
CATEGORY_LABEL,
COMPOSED_BY_LABEL,
COMPOSES_LABEL,
CONFLICTS_WITH_LABEL,
CONTRACTS_LABEL,
CONTRACT_LABEL,
DERIVED_BY_LABEL,
DETECTS_LABEL,
ENABLES_LABEL,
GROUNDED_BY_LABEL,
GROUNDS_LABEL,
PRINCIPLE_LABEL,
REFERENCED_BY_LABEL,
REINFORCES_LABEL,
REQUIRES_LABEL,
STAGE_LABEL,
TENSIONS_LABEL,
TENSIONS_WITH_LABEL,
TERM_LABEL,
} from "#configuration/strings/ontology.strings";
import {
AXIS_RELATION,
CATEGORY_RELATION,
COMPOSED_BY_RELATION,
COMPOSES_RELATION,
CONFLICTS_WITH_RELATION,
CONTRACTS_RELATION,
CONTRACT_RELATION,
DERIVED_BY_RELATION,
DETECTS_RELATION,
ENABLES_RELATION,
GROUNDED_BY_RELATION,
GROUNDS_RELATION,
PRINCIPLE_RELATION,
REFERENCED_BY_RELATION,
REINFORCES_RELATION,
REQUIRES_RELATION,
STAGE_RELATION,
TENSIONS_RELATION,
TENSIONS_WITH_RELATION,
TERM_RELATION,
} from "@govlab/constants";
import { EVIDENCE_FOR_RELATION, EVIDENCE_RELATION_ID } from "#configuration/constants/graph.constants";
import { EVIDENCE_RELATION, GROUNDS_RELATION as GROUNDS_RELATION_LABEL } from "#configuration/strings/folder.strings";
import { SPACE } from "#configuration/constants/document.constants";
export const CHAPTER_KIND_LABEL = "Chapter";
export const REFERENCE_ROLE = "tooltip";
export const REFERENCE_PANEL_LABEL = "Reference details";
export const REFERENCE_ARROW = "→";
export const CHECK_POPULATION_LABEL = "Population";
export const CHECK_FRESHNESS_LABEL = "Freshness";
export const CHECK_REFUSAL_LABEL = "Refusal";
export const CHECK_OBSERVATION_LABEL = "Observation";
export const CHECK_EVIDENCE_LABEL = "Evidence";
export const CHECK_AUTHORITY_LABEL = "Authoritative side";
export const CHECK_HEADING = "How it is checked";
export const CHECK_BY_LABEL = "Checked by";
export const CHECK_DEPENDS_ON_LABEL = "Depends on";
export const CHECK_SHAPE_LABEL = "Shape it refuses";
export const NOT_ANSWERED = "Not answered";
export const DECLARED_ABSENCE_MARK = "none:";
export const checkAnswerOf = function checkAnswerOf(answer: string | null): string {
if (answer === null) {
return NOT_ANSWERED;
}
return answer.startsWith(DECLARED_ABSENCE_MARK)
? `None, because ${answer.slice(DECLARED_ABSENCE_MARK.length).trim()}`
: answer.charAt(0).toUpperCase() + answer.slice(1);
};
const EVIDENCE_SIGN_LABELS: ReadonlyMap<string, string> = new Map([
["fires", "Watched to fire"],
["fires-and-accepts", "Watched to fire and to accept"],
["contradicted", "Measured failing"],
]);
const SIGN_SEPARATOR = ":";
export const evidenceAnswerOf = function evidenceAnswerOf(answer: string | null): string {
if (answer === null || answer.startsWith(DECLARED_ABSENCE_MARK)) {
return checkAnswerOf(answer);
}
const separator = answer.indexOf(SIGN_SEPARATOR);
const sign = answer.slice(0, separator).trim();
const label = EVIDENCE_SIGN_LABELS.get(sign);
if (separator === -1 || label === undefined) {
throw new Error(
`reference: the evidence answer "${answer}" opens with no known sign, so the check row cannot say how the check was watched`,
);
}
return `${label}: ${answer.slice(separator + 1).trim()}`;
};
const RELATION_LABELS: ReadonlyMap<string, string> = new Map([
[REQUIRES_RELATION, REQUIRES_LABEL],
[REINFORCES_RELATION, REINFORCES_LABEL],
[ENABLES_RELATION, ENABLES_LABEL],
[CONFLICTS_WITH_RELATION, CONFLICTS_WITH_LABEL],
[TENSIONS_WITH_RELATION, TENSIONS_WITH_LABEL],
[TENSIONS_RELATION, TENSIONS_LABEL],
[CONTRACTS_RELATION, CONTRACTS_LABEL],
[TERM_RELATION, TERM_LABEL],
[REFERENCED_BY_RELATION, REFERENCED_BY_LABEL],
[CATEGORY_RELATION, CATEGORY_LABEL],
[PRINCIPLE_RELATION, PRINCIPLE_LABEL],
[CONTRACT_RELATION, CONTRACT_LABEL],
[STAGE_RELATION, STAGE_LABEL],
[AXIS_RELATION, AXIS_LABEL],
[COMPOSES_RELATION, COMPOSES_LABEL],
[COMPOSED_BY_RELATION, COMPOSED_BY_LABEL],
[GROUNDS_RELATION, GROUNDS_LABEL],
[GROUNDED_BY_RELATION, GROUNDED_BY_LABEL],
[DERIVED_BY_RELATION, DERIVED_BY_LABEL],
[DETECTS_RELATION, DETECTS_LABEL],
[EVIDENCE_RELATION_ID, EVIDENCE_RELATION],
[EVIDENCE_FOR_RELATION, GROUNDS_RELATION_LABEL],
]);
const RELATION_JOINER = "-";
export const relationLabelOf = function relationLabelOf(relation: string): string {
const label = RELATION_LABELS.get(relation);
if (label !== undefined) {
return label;
}
const words = relation.split(RELATION_JOINER).join(SPACE);
return words.charAt(0).toUpperCase() + words.slice(1);
};