generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e62ae9e
commit 6989c41
Showing
6 changed files
with
56 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ExhaustiveError } from "../../errors"; | ||
import { | ||
type FactoryArgs, | ||
type Tokenizer, | ||
type TrimTarget, | ||
} from "../tokenizer"; | ||
|
||
const INPUT_TRIM_CHAR_PATTERN = /[\n\t\[\]$/:?!=()<>"',|;*~ `_“„«»‹›‚‘’”]/g; | ||
const INDEXING_TRIM_CHAR_PATTERN = /[\n\t\[\]/:?!=()<>"',|;*~ `_“„«»‹›‚‘’”]/g; | ||
|
||
export abstract class AbstractTokenizer implements Tokenizer { | ||
protected inputTrimCharPattern: RegExp; | ||
protected indexingTrimCharPattern: RegExp; | ||
|
||
constructor(_args?: FactoryArgs) { | ||
this.inputTrimCharPattern = INPUT_TRIM_CHAR_PATTERN; | ||
this.indexingTrimCharPattern = INDEXING_TRIM_CHAR_PATTERN; | ||
} | ||
|
||
getTrimPattern(target: TrimTarget): RegExp { | ||
switch (target) { | ||
case "input": | ||
return this.inputTrimCharPattern; | ||
case "indexing": | ||
return this.indexingTrimCharPattern; | ||
default: | ||
throw new ExhaustiveError(target); | ||
} | ||
} | ||
|
||
shouldIgnoreOnCurrent(_str: string): boolean { | ||
return false; | ||
} | ||
|
||
abstract tokenize(content: string, raw?: boolean): string[]; | ||
|
||
abstract recursiveTokenize( | ||
content: string | ||
): { word: string; offset: number }[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
import { ExhaustiveError } from "../../errors"; | ||
import type { TrimTarget } from "../tokenizer"; | ||
import type { FactoryArgs } from "../tokenizer"; | ||
import { DefaultTokenizer } from "./DefaultTokenizer"; | ||
|
||
const INPUT_ARABIC_TRIM_CHAR_PATTERN = /[\n\t\[\]/:?!=()<>"'.,|;*~ `،؛]/g; | ||
const INDEXING_ARABIC_TRIM_CHAR_PATTERN = /[\n\t\[\]$/:?!=()<>"'.,|;*~ `،؛]/g; | ||
|
||
export class ArabicTokenizer extends DefaultTokenizer { | ||
getTrimPattern(target: TrimTarget): RegExp { | ||
switch (target) { | ||
case "input": | ||
return INPUT_ARABIC_TRIM_CHAR_PATTERN; | ||
case "indexing": | ||
return INDEXING_ARABIC_TRIM_CHAR_PATTERN; | ||
default: | ||
throw new ExhaustiveError(target); | ||
} | ||
constructor(_args?: FactoryArgs) { | ||
super(); | ||
this.inputTrimCharPattern = INPUT_ARABIC_TRIM_CHAR_PATTERN; | ||
this.indexingTrimCharPattern = INDEXING_ARABIC_TRIM_CHAR_PATTERN; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters