@tricoteuses/tisseuse 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,10 +3,12 @@ export { assertNever } from './asserts.js';
3
3
  export { newAssembleeObjectCache, newLegifranceObjectCache, newObjectCache, type AssembleeObjectCache, type AssembleeObjectType, type LegifranceObjectCache, type ObjectCache, } from './cache.js';
4
4
  export { formatLongDate } from './dates.js';
5
5
  export { jsonReplacer } from './json.js';
6
+ export { linkTypes, urlFromLegalId, type LinkType } from './links.js';
6
7
  export { getOrLoadDocument, getOrLoadDocumentsByDossierParlementaireUid, getOrLoadDossierParlementaire, } from './loaders/assemblee.js';
7
8
  export { extendLoadedArticle, getOrLoadArticle, getOrLoadJo, getOrLoadSectionTa, getOrLoadSectionsTa, getOrLoadTextelr, getOrLoadTexteslr, getOrLoadTextesVersions, getOrLoadTexteVersion, loadArticles, type ArticleExtension, type JorfArticleExtended, type LegiArticleExtended, } from './loaders/legifrance.js';
9
+ export { walkTableOfContents, type TableOfContents, type TableOfContentsArticle, type TableOfContentsArticlePositioned, type TableOfContentsDivision, type TableOfContentsDivisionPositioned, type TableOfContentsPositioned, } from './table_of_contents.js';
8
10
  export { action } from './text_parsers/actions.js';
9
- export { article, articles, definitionArticle, designationArticle, listeArticles, nomArticle, nomSpecialArticle, } from './text_parsers/articles.js';
11
+ export { article, articles, definitionArticleDansCitation, definitionArticleDansProjetOuPropositionLoi, designationArticle, listeArticles, nomArticle, nomSpecialArticle, } from './text_parsers/articles.js';
10
12
  export { compoundReferencesSeparators, divisionTypes, europeanLawNatures, frenchLawNatures, internationalLawNatures, isTextAstAtomicReference, isTextAstDivision, isTextAstPortion, lawNatures, localizationAdverbs, portionTypes, type CompoundReferencesSeparator, type DivisionType, type EuropeanLawNature, type FrenchLawNature, type InternationalLawNature, type LawNature, type LocalizationAdverb, type PortionType, type TextAst, type TextAstAction, type TextAstArticle, type TextAstAtomicReference, type TextAstBoundedInterval, type TextAstCitation, type TextAstCompoundReference, type TextAstConseilConstitutionnelDecision, type TextAstCountedInterval, type TextAstDivision, type TextAstEnumeration, type TextAstExclusion, type TextAstIncompleteHeader, type TextAstLocalization, type TextAstNumber, type TextAstParentChild, type TextAstPortion, type TextAstPosition, type TextAstReference, type TextAstReferenceAndAction, type TextAstText, type TextAstTextIdentification, type TextAstTextInfos, type TextInfosByWordsTree, type TextInfosByWordsTreeNode, } from './text_parsers/ast.js';
11
13
  export { citation, citationLigne, citationSimple, } from './text_parsers/citations.js';
12
14
  export { date, duDate } from './text_parsers/dates.js';
@@ -14,14 +16,14 @@ export { definitionDivision, designationDivision, division, divisions, natureDiv
14
16
  export type { FragmentPosition, FragmentReverseTransformation, } from './text_parsers/fragments.js';
15
17
  export { addChildLeftToLastChild, createEnumerationOrBoundedInterval, createParentChildTreeFromReferences, iterAtomicFirstParentReferences, iterAtomicReferences, iterIncludedReferences, } from './text_parsers/helpers.js';
16
18
  export { getParsedReferences, getParsedReferencesWithOriginalTransformations, parseCitationReferences, parseReferences, parseReferencesWithOriginalTransformations, } from './text_parsers/index.js';
17
- export { parseTextLinks, type ArticleDefinition, type ArticleExternalLink, type ArticleInternalLink, type ArticleLink, type DefinitionOrLink, type DivisionExternalLink, type DivisionLink, type ExtractedLinkDb, type TextExternalLink, type TextLink, type TextLinksParserState, } from './text_parsers/links.js';
19
+ export { iterReferenceLinks, parseTextLinks, type ArticleDefinition, type ArticleExternalLink, type ArticleInternalLink, type ArticleLink, type DefinitionOrLink, type DivisionExternalLink, type DivisionLink, type ExtractedLinkDb, type TextExternalLink, type TextLink, type TextLinksParserState, } from './text_parsers/links.js';
18
20
  export { adjectifNumeralOrdinalCourt, adverbeMultiplicatifLatin, nombreAsTextAstNumber, nombreCardinal, nombreRomainCardinal, nombreRomainOrdinal, nombreRomainOu0iAsTextAstNumber, } from './text_parsers/numbers.js';
19
21
  export { alternatives, chain, convert, optional, parseText, regExp, repeat, TextParserContext, variable, wordsTree, } from './text_parsers/parsers.js';
20
22
  export { auPortion, auxPortions, numeroPortion, portions, unePortion, } from './text_parsers/portions.js';
21
23
  export { ditPluriel, ditSingulier, introPluriel, introSingulier, liaisonPluriel, liaisonSingulier, } from './text_parsers/prepositions.js';
22
- export { reference, uniteBasePreciseeSingulier, uniteBaseSingulier, } from './text_parsers/references.js';
24
+ export { listeReferencesSeules, reference, referenceSeule, uniteBasePreciseeSingulier, uniteBaseSingulier, } from './text_parsers/references.js';
23
25
  export { adverbeRelatif, espaceAdverbeRelatif, relatifPlurielPrepose, relatifSingulierPrepose, } from './text_parsers/relative_locations.js';
24
- export { convertHtmlElementsToText, decodeNamedHtmlEntities, decodeNumericHtmlEntities, replacePattern, replacePatterns, simplifyHtml, simplifyText, simplifyUnicodeCharacters, } from './text_parsers/simplifiers.js';
26
+ export { convertHtmlElementsToText, decodeNamedHtmlEntities, decodeNumericHtmlEntities, replaceHtmlPatterns, replacePattern, replaceTextPatterns, simplifyHtml, simplifyPlainText, simplifyText, simplifyUnicodeCharacters, } from './text_parsers/simplifiers.js';
25
27
  export { definitionTexteFrancais, identificationTexteEuropeen, natureTexteFrancais, numeroEtOuDateTexteFrancais, numeroTexteEuropeen, numeroTexteFrancais, optionalEspaceDuTerritoire, texte, texteEuropeen, texteFrancais, texteInternational, } from './text_parsers/texts.js';
26
28
  export { chainTransformers, newReverseTransformationsMergedFromPositionsIterator, reversePositionsSplitFromPositions, reverseTransformationsMergedFromPositions, reverseTransformationFromPosition, reverseTransformedInnerFragment, reverseTransformedReplacement, type SourceMapSegment, type Transformation, type TransformationLeaf, type TransformationNode, type Transformer, type TransformerLeaf, type TransformerNode, } from './text_parsers/transformers.js';
27
29
  export { espace, lettreAsciiMinuscule, nonLettre, numero, virguleOuEspace, } from './text_parsers/typography.js';
@@ -0,0 +1 @@
1
+ export { readTransformation, writeTransformation, } from './text_parsers/transformers.js';
@@ -0,0 +1,31 @@
1
+ import { DivisionType } from './text_parsers/ast.js';
2
+ import { FragmentPosition, FragmentReverseTransformation } from './text_parsers/fragments.js';
3
+ export interface TableOfContents {
4
+ articles?: TableOfContentsArticle[];
5
+ divisions?: TableOfContentsDivision[];
6
+ }
7
+ export interface TableOfContentsArticle {
8
+ line: string;
9
+ type: "article";
10
+ }
11
+ export type TableOfContentsArticlePositioned = TableOfContentsArticle & {
12
+ originalTransformation: FragmentReverseTransformation;
13
+ position: FragmentPosition;
14
+ };
15
+ export interface TableOfContentsDivision {
16
+ articles?: TableOfContentsArticle[];
17
+ divisions?: TableOfContentsDivision[];
18
+ line: string;
19
+ type: DivisionType;
20
+ }
21
+ export type TableOfContentsDivisionPositioned = TableOfContentsDivision & {
22
+ articles?: TableOfContentsArticlePositioned[];
23
+ divisions?: TableOfContentsDivisionPositioned[];
24
+ originalTransformation: FragmentReverseTransformation;
25
+ position: FragmentPosition;
26
+ };
27
+ export interface TableOfContentsPositioned {
28
+ articles?: TableOfContentsArticlePositioned[];
29
+ divisions?: TableOfContentsDivisionPositioned[];
30
+ }
31
+ export declare function walkTableOfContents(tableOfContents: TableOfContents | TableOfContentsDivision): Generator<TableOfContentsArticle | TableOfContentsDivision, void, unknown>;
@@ -18,7 +18,7 @@ export declare const typeArticle: import('./parsers.js').TextParser;
18
18
  */
19
19
  export declare const nomArticle: import('./parsers.js').TextParser;
20
20
  /**
21
- * Numéro d’article, utilisé lors de sa definition,
21
+ * Numéro d’article, utilisé lors de sa définition,
22
22
  * par exemple « L.O 113-1 » ou « L328-1 A bis-0 » ou « préliminaire »
23
23
  * Attention cette règle est plus stricte que nomArticle, car, par exemple,
24
24
  * dans la ligne :
@@ -27,10 +27,25 @@ export declare const nomArticle: import('./parsers.js').TextParser;
27
27
  */
28
28
  export declare const nomArticleDefinition: import('./parsers.js').TextParser;
29
29
  /**
30
- * Déclaration d'un article
30
+ * Numéro d’article à l'intérieur d'un projet ou d'une proposition de loi
31
+ *
32
+ * Dans un projet (ou une proposition) de loi initial, un numéro d'article
33
+ * est un simple nombre ou un nom spécial.
34
+ * Dans les versions suivantes, le numéro d'article est un nombre éventuellement
35
+ * suivi d'un adverbe multiplicatif latin.
36
+ */
37
+ export declare const nomArticleProjetOuPropositionLoi: import('./parsers.js').TextParser;
38
+ /**
39
+ * Déclaration d'un article au sein d'une citation dans un projet
40
+ * ou une proposition de loi
31
41
  * Exemple : « Art. L. 322‑66. - blablabla… en début de ligne
32
42
  */
33
- export declare const definitionArticle: import('./parsers.js').TextParser;
43
+ export declare const definitionArticleDansCitation: import('./parsers.js').TextParser;
44
+ /**
45
+ * Déclaration d'un article dans un projet ou une proposition de loi
46
+ * Exemple : « Article 2 » en début de ligne
47
+ */
48
+ export declare const definitionArticleDansProjetOuPropositionLoi: import('./parsers.js').TextParser;
34
49
  /**
35
50
  * Désignation d’un article, de façon absolue (avec son numero ou nom) ou relative (précédent, suivant, …)
36
51
  */
@@ -15,6 +15,7 @@ export interface TextAstAction {
15
15
  }
16
16
  export type TextAstArticle = {
17
17
  definition?: boolean;
18
+ definitionSuffix?: string;
18
19
  implicitText?: TextAstText | undefined;
19
20
  localizationAdverb?: LocalizationAdverb;
20
21
  ofTheSaid?: boolean;
@@ -43,6 +44,7 @@ export type TextAstCountedInterval = {
43
44
  } & TextAstPosition;
44
45
  export type TextAstDivision = {
45
46
  definition?: boolean;
47
+ definitionSuffix?: string;
46
48
  ofTheSaid?: boolean;
47
49
  type: DivisionType;
48
50
  } & TextAstLocalization & TextAstPosition;
@@ -88,6 +88,22 @@ export interface TextLinksParserState {
88
88
  sectionTaId?: string;
89
89
  textId?: string;
90
90
  }
91
+ export declare function iterReferenceLinks({ articleDefinitionByNumByTextId: articleDefinitionByNumByTextIdInput, context, date, legiDb, logIgnoredReferencesTypes, logPartialReferences, originalPositionsFromTransformedIterator, reference, state: inputState, }: {
92
+ articleDefinitionByNumByTextId?: Record<string, Record<string, ArticleDefinition>>;
93
+ context: TextParserContext;
94
+ date: string;
95
+ legiDb: Sql;
96
+ logIgnoredReferencesTypes?: boolean;
97
+ logPartialReferences?: boolean;
98
+ originalPositionsFromTransformedIterator?: Generator<FragmentReverseTransformation, void, FragmentPosition | undefined>;
99
+ reference: TextAstReference;
100
+ /**
101
+ * When given, state is modified by this generator, so that the callers
102
+ * always has the latest state version (and can reuse it for the next article,
103
+ * for example).
104
+ */
105
+ state?: TextLinksParserState;
106
+ }): AsyncGenerator<DefinitionOrLink>;
91
107
  export declare function parseTextLinks({ context, date, legiDb, logIgnoredReferencesTypes, logPartialReferences, logReferences, state: inputState, transformation, }: {
92
108
  context: TextParserContext;
93
109
  date: string;
@@ -11,3 +11,5 @@ export declare const referencePluriel1Internal: import('./parsers.js').TextParse
11
11
  export declare const referenceSingulier1Internal: import('./parsers.js').TextParser;
12
12
  export declare const reference1Internal: import('./parsers.js').TextParser;
13
13
  export declare const reference: import('./parsers.js').TextParser;
14
+ export declare const referenceSeule: import('./parsers.js').TextParser;
15
+ export declare const listeReferencesSeules: import('./parsers.js').TextParser;
@@ -4,10 +4,12 @@ export declare function convertHtmlElementsToText({ removeAWithHref, }?: {
4
4
  }): TransformerLeaf;
5
5
  export declare function decodeNamedHtmlEntities(input: string): TransformationLeaf;
6
6
  export declare function decodeNumericHtmlEntities(input: string): TransformationLeaf;
7
+ export declare function replaceHtmlPatterns(input: string): TransformationNode;
7
8
  export declare function replacePattern(pattern: RegExp | string, replacement: string): TransformerLeaf;
8
- export declare function replacePatterns(input: string): TransformationNode;
9
+ export declare function replaceTextPatterns(input: string): TransformationNode;
9
10
  export declare function simplifyHtml({ removeAWithHref, }?: {
10
11
  removeAWithHref?: boolean;
11
12
  }): TransformerNode;
13
+ export declare function simplifyPlainText(input: string): TransformationNode;
12
14
  export declare function simplifyText(input: string): TransformationNode;
13
15
  export declare function simplifyUnicodeCharacters(input: string): TransformationLeaf;
@@ -44,7 +44,8 @@ export declare function chainTransformers(title: string, transformers: Array<Tra
44
44
  export declare function newReverseTransformationsMergedFromPositionsIterator(transformation: Transformation): Generator<FragmentReverseTransformation, void, FragmentPosition | undefined>;
45
45
  /**
46
46
  * Converts an array of transformed (e.g. simplified) positions to an array
47
- * of original (e.g. HTML) positions
47
+ * of arrays of original (e.g. HTML) positions (one array of original positions
48
+ * for each transformed position)
48
49
  *
49
50
  * Each position is split to ensure that it doesn't contain any HTML element.
50
51
  *
@@ -52,7 +53,7 @@ export declare function newReverseTransformationsMergedFromPositionsIterator(tra
52
53
  *
53
54
  * Use this function for diffs.
54
55
  */
55
- export declare function reversePositionsSplitFromPositions(transformation: Transformation, positions: Array<FragmentPosition[]>): Array<FragmentPosition[]>;
56
+ export declare function reversePositionsSplitFromPositions(transformation: Transformation, transformedPositions: FragmentPosition[]): Array<FragmentPosition[]>;
56
57
  /**
57
58
  * Converts an array of transformed (e.g. simplified) positions to an array
58
59
  * of original (e.g. HTML) positions
@@ -0,0 +1,30 @@
1
+ /**
2
+ * TODO;
3
+ * Ce script devrait travailler sur Documents_enrichi, mais ce n'est pas le seul.
4
+ * Car il y a un script qui met les liens, etc.
5
+ * Documents_enrichi doit contenir tout ce que contient Documents (sauf éventuellement des formats inutiles).
6
+ * Il faut donc un script de syncronisation entre Documents et Documents_enrichi, qui (re)lance plusieurs scripts
7
+ * quand quelque chose a changé entre les fichiers d'un Documents et ceux d'un Documents_enrichi.
8
+ * Problème : le script de synchronisation devrait faire partie de @tricoteuses/assemblee.
9
+ * Mais les scripts qui mettent les liens et ce script qui détecte la structure doit faire partie de @tricoteuses/tisseuse.
10
+ * Quand le script de synchronisation détecte qu'une document (quelque soit son format a changé ou a été ajouté ou…) il devrait
11
+ * lancer tisseuse.
12
+ * Pas de problème car c'est tricoteuses-assemblee-update qui gère tout cela et tricoteuses-assemblee-update peut aussi bien
13
+ * lancer des scripts assemblee que des scripts tisseuse.
14
+ *
15
+ * Ce script parse_bill_structure travaille sur un seul document (dans Documents_enrichi) dont le chemin lui est fourni.
16
+ * Il suppose que le script simplify_assemblee_document, qui simplifie le document (et qui créé les fichiers intermédiaires
17
+ * dans le répertoire) est déjà passé.
18
+ *
19
+ * Il y a deux scripts (ou deux modes d'appel du même script) :
20
+ * * un qui extrait un JSON contenant l'arborescence des sections et des articles avec seulement le contenu de la ligne
21
+ * Cela permet d'éditer ce fichier avec un éditeur et d'y ajouter manuellement les sections non détectées par ce script.
22
+ * Attention, quand on repasse le script il ne faut pas modifier le fichier qui a été modifié manuellement
23
+ * => 2 fichiers distincts !
24
+ * * un qui part de ce fichier, retrouve les lignes dans le fichier texte et mémorise dans un autre fichier json la
25
+ * position de début et de fin dans texte et dans le HTML de chacune des sections et chacun des articles.
26
+ * * pour faire le diff entre ce document et un autre, il n'y a plus qu'à utiliser les fichiers json des 2 documents pour
27
+ * trouver les positions (dans le texte) des articles à comparer, faire le diff pour chacun des articles et le montrer dans
28
+ * le HTML en ajoutant les élements HTML adéquats.
29
+ */
30
+ export {};
package/dist/server.js ADDED
@@ -0,0 +1,76 @@
1
+ import e from "fs-extra";
2
+ import c from "node:path";
3
+ function y(n, o) {
4
+ const t = "transformation_", r = ".json", i = {};
5
+ for (const f of e.readdirSync(o).toSorted())
6
+ if (f.startsWith(t) && f.endsWith(r)) {
7
+ const a = f.slice(
8
+ t.length,
9
+ -r.length
10
+ ), m = a.split(".").map((u) => parseInt(u) - 1);
11
+ let s = i;
12
+ for (const u of m.slice(1)) {
13
+ const l = s.transformations ??= [];
14
+ for (; u >= l.length; )
15
+ l.push({});
16
+ s = l[u];
17
+ }
18
+ s.output = e.readFileSync(
19
+ c.join(o, `${t}${a}.html`),
20
+ {
21
+ encoding: "utf-8"
22
+ }
23
+ );
24
+ const { sourceMap: d, title: h } = e.readJsonSync(
25
+ c.join(o, f),
26
+ {
27
+ encoding: "utf-8"
28
+ }
29
+ );
30
+ d !== void 0 && (s.sourceMap = d), s.title = h;
31
+ }
32
+ return p(i, n), i;
33
+ }
34
+ function p(n, o) {
35
+ if (n.input = o, n.transformations !== void 0)
36
+ for (const t of n.transformations)
37
+ p(t, o), o = t.output;
38
+ return o;
39
+ }
40
+ function j(n, o, t = "1") {
41
+ if (e.ensureDirSync(o), n.transformations === void 0)
42
+ e.writeJsonSync(
43
+ c.join(o, `transformation_${t}.json`),
44
+ {
45
+ sourceMap: n.sourceMap,
46
+ title: n.title
47
+ },
48
+ { encoding: "utf-8", spaces: 2 }
49
+ );
50
+ else {
51
+ e.writeJsonSync(
52
+ c.join(o, `transformation_${t}.json`),
53
+ {
54
+ title: n.title
55
+ },
56
+ { encoding: "utf-8", spaces: 2 }
57
+ );
58
+ for (const [r, i] of n.transformations.entries())
59
+ j(
60
+ i,
61
+ o,
62
+ `${t}.${r + 1}`
63
+ );
64
+ }
65
+ n.output !== void 0 && e.writeFileSync(
66
+ c.join(o, `transformation_${t}.html`),
67
+ n.output,
68
+ {
69
+ encoding: "utf-8"
70
+ }
71
+ );
72
+ }
73
+ export {
74
+ y as readTransformation,
75
+ j as writeTransformation
76
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tricoteuses/tisseuse",
3
3
  "description": "Find links in/to French legislative documents",
4
- "version": "0.6.0",
4
+ "version": "0.8.0",
5
5
  "keywords": [
6
6
  "Assemblée nationale",
7
7
  "France",
@@ -36,6 +36,11 @@
36
36
  "import": "./dist/index.js",
37
37
  "types": "./dist/lib/index.d.ts"
38
38
  },
39
+ "./server": {
40
+ "typedoc": "./src/server/index.ts",
41
+ "import": "./dist/server.js",
42
+ "types": "./dist/lib/server/index.d.ts"
43
+ },
39
44
  "./package.json": "./package.json"
40
45
  },
41
46
  "publishConfig": {
@@ -52,7 +57,7 @@
52
57
  },
53
58
  "devDependencies": {
54
59
  "@auditors/core": "^0.7.4",
55
- "@tricoteuses/assemblee": "^2.4.3",
60
+ "@tricoteuses/assemblee": "^2.5.2",
56
61
  "@tricoteuses/legifrance": "^0.16.0",
57
62
  "@types/fs-extra": "^11.0.4",
58
63
  "@types/node": "^24.8.1",