Skip to content

Commit

Permalink
[Improvements] Update all test to use new Wordt to line implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jvalls-axa committed Jul 1, 2020
1 parent cd79564 commit ded01c8
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
Expand Up @@ -20,7 +20,7 @@ import { KeyValueMetadata } from '../../types/Metadata/KeyValueMetadata';
import { getSubCollections } from '../../utils';
import logger from '../../utils/Logger';
import { Module } from '../Module';
import { WordsToLineModule } from '../WordsToLineModule/WordsToLineModule';
import { WordsToLineNewModule } from '../WordsToLineNewModule/WordsToLineNew';
import * as defaultConfig from './defaultConfig.json';

interface Options {
Expand All @@ -44,7 +44,7 @@ export type KeyCandidate = {
*/
export class KeyValueDetectionModule extends Module<Options> {
public static moduleName = 'key-value-detection';
public static dependencies = [WordsToLineModule];
public static dependencies = [WordsToLineNewModule];

constructor(options?: Options) {
super(options, defaultOptions);
Expand Down
4 changes: 2 additions & 2 deletions server/src/processing/TemplateModule/TemplateModule.ts
Expand Up @@ -17,7 +17,7 @@
import { Document } from '../../types/DocumentRepresentation';
import logger from '../../utils/Logger';
import { Module } from '../Module';
import { WordsToLineModule } from '../WordsToLineModule/WordsToLineModule';
import { WordsToLineNewModule } from '../WordsToLineNewModule/WordsToLineNew';
import * as defaultConfig from './defaultConfig.json';

// List of every options you need.
Expand All @@ -39,7 +39,7 @@ export class TemplateModule extends Module<Options> {
// If your module can only be ran after another module, add it to the list.
// For instance, if your module needs a document where lines have already be created,
// you need to add `WordsToLineModule` as a dependency.
public static dependencies = [WordsToLineModule];
public static dependencies = [WordsToLineNewModule];

// This constructor ensures options and default options will be correctly copied.
constructor(options?: Options) {
Expand Down
8 changes: 4 additions & 4 deletions test/input-extractors.spec.ts
Expand Up @@ -25,7 +25,7 @@ import { LinesToParagraphModule } from '../server/src/processing/LinesToParagrap
import { OutOfPageRemovalModule } from '../server/src/processing/OutOfPageRemovalModule/OutOfPageRemovalModule';
import { ReadingOrderDetectionModule } from '../server/src/processing/ReadingOrderDetectionModule/ReadingOrderDetectionModule';
import { WhitespaceRemovalModule } from '../server/src/processing/WhitespaceRemovalModule/WhitespaceRemovalModule';
import { WordsToLineModule } from '../server/src/processing/WordsToLineModule/WordsToLineModule';
import { WordsToLineNewModule } from '../server/src/processing/WordsToLineNewModule/WordsToLineNew';
import { Document, Paragraph } from '../server/src/types/DocumentRepresentation';
import { runModules } from './helpers';

Expand Down Expand Up @@ -63,7 +63,7 @@ describe('PDF.js input module', () => {
new OutOfPageRemovalModule(),
new WhitespaceRemovalModule(),
new ReadingOrderDetectionModule(),
new WordsToLineModule(),
new WordsToLineNewModule(),
new LinesToParagraphModule(),
]).then(doc => {
exportedText = doc
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('EML input module', () => {
new OutOfPageRemovalModule(),
new WhitespaceRemovalModule(),
new ReadingOrderDetectionModule(),
new WordsToLineModule(),
new WordsToLineNewModule(),
new LinesToParagraphModule(),
]).then(doc => {
docAfter = doc;
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('MS Word input module', () => {
new OutOfPageRemovalModule(),
new WhitespaceRemovalModule(),
new ReadingOrderDetectionModule(),
new WordsToLineModule(),
new WordsToLineNewModule(),
new LinesToParagraphModule(),
]).then(doc => {
docAfter = doc;
Expand Down
4 changes: 2 additions & 2 deletions test/json-export-import.spec.ts
Expand Up @@ -21,7 +21,7 @@ import { JsonExporter } from '../server/src/output/json/JsonExporter';
import { HierarchyDetectionModule } from '../server/src/processing/HierarchyDetectionModule/HierarchyDetectionModule';
import { LinesToParagraphModule } from '../server/src/processing/LinesToParagraphModule/LinesToParagraphModule';
import { ReadingOrderDetectionModule } from '../server/src/processing/ReadingOrderDetectionModule/ReadingOrderDetectionModule';
import { WordsToLineModule } from '../server/src/processing/WordsToLineModule/WordsToLineModule';
import { WordsToLineNewModule } from '../server/src/processing/WordsToLineNewModule/WordsToLineNew';
import { Document, Element, JsonExport } from '../server/src/types/DocumentRepresentation';
import { json2document } from '../server/src/utils/json2document';
import { getDocFromJson, runModules } from './helpers';
Expand All @@ -41,7 +41,7 @@ describe('JSON export and import', () => {
Element.resetGlobalId();
return runModules(json, [
new ReadingOrderDetectionModule(),
new WordsToLineModule(),
new WordsToLineNewModule(),
new LinesToParagraphModule(),
new HierarchyDetectionModule(),
]);
Expand Down
4 changes: 2 additions & 2 deletions test/line-merge.spec.ts
Expand Up @@ -18,7 +18,7 @@ import { expect } from 'chai';
import { withData } from 'leche';
import 'mocha';
import { ReadingOrderDetectionModule } from '../server/src/processing/ReadingOrderDetectionModule/ReadingOrderDetectionModule';
import { WordsToLineModule } from '../server/src/processing/WordsToLineModule/WordsToLineModule';
import { WordsToLineNewModule } from '../server/src/processing/WordsToLineNewModule/WordsToLineNew';
import { Document, Element } from '../server/src/types/DocumentRepresentation';
import { getDocFromJson, runModules } from './helpers';

Expand All @@ -36,7 +36,7 @@ describe('Line merge function', () => {

before(done => {
function transform(json: Document) {
return runModules(json, [new ReadingOrderDetectionModule(), new WordsToLineModule()]);
return runModules(json, [new ReadingOrderDetectionModule(), new WordsToLineNewModule()]);
}

getDocFromJson(transform, jsonName).then(after => {
Expand Down
6 changes: 3 additions & 3 deletions test/paragraph-merge.spec.ts
Expand Up @@ -26,7 +26,7 @@ import {
import { WhitespaceRemovalModule } from '../server/src/processing/WhitespaceRemovalModule/WhitespaceRemovalModule';

import * as fs from 'fs';
import { WordsToLineModule } from '../server/src/processing/WordsToLineModule/WordsToLineModule';
import { WordsToLineNewModule } from '../server/src/processing/WordsToLineNewModule/WordsToLineNew';
import { Paragraph } from '../server/src/types/DocumentRepresentation';
import { Document } from '../server/src/types/DocumentRepresentation/Document';
import { getDocFromJson, runModules, TableExtractorStub } from './helpers';
Expand All @@ -44,8 +44,8 @@ function executePipeLine(jsonName: string, done, tableExtractor?: TableExtractor
new OutOfPageRemovalModule(),
new WhitespaceRemovalModule(),
tableDetectionModule,
new WordsToLineNewModule(),
new ReadingOrderDetectionModule(),
new WordsToLineModule(),
new LinesToParagraphModule(),
]);
}
Expand Down Expand Up @@ -126,6 +126,6 @@ describe('Paragraph merge function with tables ans more', () => {
it('should merge side-by-side lines into paragraphs', () => {
expect(docAfter.pages[0].getElementsOfType<Paragraph>(Paragraph, true))
.to.be.an('array')
.and.to.be.of.length(52);
.and.to.be.of.length(54);
});
});
15 changes: 8 additions & 7 deletions test/words-to-line.spec.ts
Expand Up @@ -17,7 +17,7 @@
import { expect } from 'chai';
import { withData } from 'leche';
import 'mocha';
import { WordsToLineModule } from '../server/src/processing/WordsToLineModule/WordsToLineModule';
import { WordsToLineNewModule } from '../server/src/processing/WordsToLineNewModule/WordsToLineNew';
import { Document, Line, Word } from '../server/src/types/DocumentRepresentation';
import { getDocFromJson, runModules } from './helpers';

Expand Down Expand Up @@ -54,12 +54,13 @@ describe('Words to Line Module', () => {
return doc;
}

getDocFromJson(doc => runModules(sortWords(doc), [new WordsToLineModule()]), fileName).then(
after => {
docAfter = after;
done();
},
);
getDocFromJson(
doc => runModules(sortWords(doc), [new WordsToLineNewModule()]),
fileName,
).then(after => {
docAfter = after;
done();
});
});

it('should merge side-by-side words into a single block', () => {
Expand Down

0 comments on commit ded01c8

Please sign in to comment.