Code Explainers

Code explainers tagged #text-processing

ruby
class SnippetHighlighter
  CONTEXT_RADIUS = 60
  MAX_TERMS = 8
 

Building search-result snippets in Ruby

regular-expressions text-processing search
Intermediate 9 steps
java
public final class ImportOrganizer {
 
    private static final Pattern IMPORT_LINE =
            Pattern.compile("^import\\s+(static\\s+)?([\\w.]+(?:\\.\\*)?)\\s*;\\s*$");

Sorting Java imports with a regex pass

regex sorting text-processing
Intermediate 8 steps
php
<?php
 
namespace App\Services;
 

Building a profanity filter in PHP

regex text-processing immutability
Intermediate 6 steps
ruby
require "charlock_holmes"
 
class TextFileNormalizer
  DEFAULT_CONFIDENCE = 60

Normalizing text files to clean UTF-8 in Ruby

encoding text-processing file-io
Intermediate 8 steps
python
import heapq
from collections import Counter
from typing import Iterable, Hashable
 

Finding the top-N items in a stream

heaps counting generators
Intermediate 5 steps
php
<?php
 
final class MarkdownParser
{

Building a small Markdown-to-HTML parser in PHP

state-machine parsing closures
Intermediate 10 steps
python
import re
from collections import Counter
from pathlib import Path
 

Ranking the top words in a PDF

text-processing regex counting
Intermediate 6 steps
rust
use std::collections::HashMap;
 
pub fn word_frequencies(text: &str) -> HashMap<String, usize> {
    let mut counts: HashMap<String, usize> = HashMap::new();

Counting and ranking words in Rust

hashmap iterators sorting
Intermediate 7 steps