| Author | Dave Jarvis <email> |
|---|---|
| Date | 2022-08-20 23:12:23 GMT-0700 |
| Commit | e1b113c04f0691926a7aee14058b6025b7f48577 |
| Parent | e5d7b11 |
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| +import java.util.List; | ||
| import java.util.function.Consumer; | ||
| Collections.sort( tokens ); | ||
| + | ||
| + // All laggards appearing before the first leader are apostrophes. | ||
| + resolve( tokens ); | ||
| + | ||
| + // Replacing laggards may have made leaders resolvable. | ||
| + mTree.visit( this::disambiguate ); | ||
| // Relay the tokens, in order, for updating the parsed document. | ||
| tokens.forEach( mConsumer ); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Converts all laggards into apostrophes up until the first leader is found. | ||
| + * | ||
| + * @param tokens The list of sorted {@link Token}s to convert. | ||
| + */ | ||
| + private void resolve( final List<Token> tokens ) { | ||
| + assert tokens != null; | ||
| + | ||
| + for( final var token : tokens ) { | ||
| + if( token.isType( QUOTE_AMBIGUOUS_LEADING ) ) { | ||
| + // Once a leader quote is found, any laggard could be a closing quote. | ||
| + break; | ||
| + } | ||
| + else if( token.isType( QUOTE_AMBIGUOUS_LAGGING ) ) { | ||
| + token.setTokenType( QUOTE_APOSTROPHE ); | ||
| + } | ||
| + } | ||
| } | ||
| // what's up|to eat | ||
| "sup", | ||
| - // cannot (tan't)|melanin | ||
| + // cannot (tan't)|colour | ||
| "tan", | ||
| // still|turn soil |
| * @param parserType Creates a parser based on document content structure. | ||
| */ | ||
| - public Curler( | ||
| - final Contractions c, | ||
| - final FilterType parserType | ||
| - ) { | ||
| + public Curler( final Contractions c, final FilterType parserType ) { | ||
| this( c, ENTITIES, parserType ); | ||
| } |
| import com.whitemagicsoftware.keenquotes.lex.FilterType; | ||
| +import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| */ | ||
| @ParameterizedTest | ||
| - @ValueSource( strings = {"habberton"} ) | ||
| - //@Disabled | ||
| + @ValueSource( strings = {"autonoma"} ) | ||
| + @Disabled | ||
| void test_Parse_Story_Converted( final String filename ) throws IOException { | ||
| final var sb = new StringBuilder( 2 ^ 20 ); | ||
| - try( final var reader = open( filename + ".txt" ) ) { | ||
| + try( final var reader = open( filename + ".html" ) ) { | ||
| String line; | ||
| while( (line = reader.readLine()) != null ) { | ||
| sb.append( line ).append( SEP ); | ||
| } | ||
| } | ||
| - final var converter = createCurler( FILTER_PLAIN ); | ||
| - System.out.println( converter.apply( sb.toString() ) ); | ||
| + final var curler = createCurler( FILTER_XML ); | ||
| + System.out.println( curler.apply( sb.toString() ) ); | ||
| } | ||
| # Mixed | ||
| # ######################################################################## | ||
| -#"Granpa Harry 'spects you, Miss Mayton." | ||
| -#“Granpa Harry 'spects you, Miss Mayton.” | ||
| +"Granpa Harry 'spects you, Miss Mayton." | ||
| +“Granpa Harry 'spects you, Miss Mayton.” | ||
| "She said, 'That's Sam's'," said the Sams' cat. |
| <a href="https://x.org" title="X's Homepage">X11's bomb</a> | ||
| +<body><p>Test lungs' capacity; shovel's handle hit his head's electronics.</p><p>Hoped to bring him 'round.</p></body> | ||
| +<body><p>Test lungs' capacity; shovel's handle hit his head's electronics.</p><p>Hoped to bring him 'round.</p></body> | ||
| + |
| Delta | 39 lines added, 12 lines removed, 27-line increase |
|---|