Documentation
¶
Overview ¶
Package converter provides contextual word conversion configuration functionality
Package converter provides contextual word detection functionality ¶
Package converter provides contextual word detection functionality for grammatically-aware text conversion ¶
Package converter provides functionality to convert between American and British English spellings ¶
Package converter provides unit conversion configuration functionality ¶
Package converter provides unit conversion functionality ¶
Package converter provides unit detection functionality ¶
Package converter provides unit detection patterns and regex
Index ¶
- Variables
- func CreateExampleUserConfig() error
- func CreateUserConfigDirectory() error
- func CreateUserConfigurationTemplate() error
- func ExtractMatchedWord(match []string, baseWord string) string
- func ExtractUnitFromMatch(match []string, unitNames []string) string
- func GetConfigStatus() (map[string]interface{}, error)
- func GetUserConfigPath() (string, error)
- func SaveContextualWordConfig(config *ContextualWordConfig) error
- func SaveUserConfig(config *UnitConfig) error
- func ValidateConfig(config *UnitConfig) error
- type BasicUnitConverter
- type CodeBlock
- type CommentBlock
- type ContextAwareWordDetector
- func (d *ContextAwareWordDetector) DetectWords(text string) []ContextualWordMatch
- func (d *ContextAwareWordDetector) GetConfig() *ContextualWordConfig
- func (d *ContextAwareWordDetector) GetConfiguration() *ContextualWordConfig
- func (d *ContextAwareWordDetector) IsEnabled() bool
- func (d *ContextAwareWordDetector) SetConfig(config *ContextualWordConfig)
- func (d *ContextAwareWordDetector) SetEnabled(enabled bool)
- func (d *ContextAwareWordDetector) SetMinConfidence(confidence float64)
- func (d *ContextAwareWordDetector) SupportedWords() []string
- func (d *ContextAwareWordDetector) UpdateConfiguration(config *ContextualWordConfig)
- type ContextualMapping
- type ContextualUnitDetector
- type ContextualWordConfig
- func (c *ContextualWordConfig) AddCustomWord(baseWord, nounForm, verbForm string)
- func (c *ContextualWordConfig) AddExclusionPattern(pattern string)
- func (c *ContextualWordConfig) DisableWord(baseWord string)
- func (c *ContextualWordConfig) EnableWord(baseWord string)
- func (c *ContextualWordConfig) GetMappingForWord(word string) (ContextualMapping, bool)
- func (c *ContextualWordConfig) GetSupportedWords() []string
- func (c *ContextualWordConfig) GetWordConfig(word string) (WordConfig, bool)
- func (c *ContextualWordConfig) IsWordSupported(word string) bool
- func (c *ContextualWordConfig) RemoveCustomWord(baseWord string)
- func (c *ContextualWordConfig) RemoveExclusionPattern(pattern string)
- type ContextualWordDetector
- type ContextualWordMatch
- type ContextualWordPattern
- type ContextualWordPatterns
- func (p *ContextualWordPatterns) AddWordConfig(word string, config WordConfig)
- func (p *ContextualWordPatterns) GetAllPatterns() map[string][]ContextualWordPattern
- func (p *ContextualWordPatterns) GetPatternsForWord(baseWord string) []ContextualWordPattern
- func (p *ContextualWordPatterns) GetSupportedWords() []string
- func (p *ContextualWordPatterns) GetWordConfig(word string) (WordConfig, bool)
- func (p *ContextualWordPatterns) IsExcluded(text string) bool
- type ContextualWordPreferences
- type ConversionPreferences
- type ConversionResult
- type Converter
- func (c *Converter) ConvertToBritish(text string, normaliseSmartQuotes bool) string
- func (c *Converter) ConvertToBritishSimple(text string, normaliseSmartQuotes bool) string
- func (c *Converter) DetectCodeBlocks(text string) []CodeBlock
- func (c *Converter) ExtractComments(code, language string) []CommentBlock
- func (c *Converter) GetAmericanToBritishDictionary() map[string]string
- func (c *Converter) GetContextualWordDetector() ContextualWordDetector
- func (c *Converter) GetUnitProcessor() *UnitProcessor
- func (c *Converter) IsContextualWordDetectionEnabled() bool
- func (c *Converter) ProcessCodeAware(text string, normaliseSmartQuotes bool) string
- func (c *Converter) SetContextualWordDetectionEnabled(enabled bool)
- func (c *Converter) SetUnitProcessingEnabled(enabled bool)
- type DetectionConfig
- type Dictionaries
- type GeneralPattern
- type SentenceAwareConverter
- func (sac *SentenceAwareConverter) ConvertToBritishSimple(text string, normaliseSmartQuotes bool) string
- func (sac *SentenceAwareConverter) ConvertToBritishWithSentenceAwareness(text string, normaliseSmartQuotes bool) string
- func (sac *SentenceAwareConverter) GetContextualWordDetector() ContextualWordDetector
- func (sac *SentenceAwareConverter) GetConverter() *Converter
- func (sac *SentenceAwareConverter) IsContextualWordDetectionEnabled() bool
- func (sac *SentenceAwareConverter) SetContextualWordDetectionEnabled(enabled bool)
- type TextPart
- type TextSegment
- type UnitConfig
- func (c *UnitConfig) Clone() *UnitConfig
- func (c *UnitConfig) GetPrecisionForUnitType(unitType UnitType) int
- func (c *UnitConfig) IsUnitTypeEnabled(unitType UnitType) bool
- func (c *UnitConfig) MarshalJSON() ([]byte, error)
- func (c *UnitConfig) Merge(other *UnitConfig)
- func (c *UnitConfig) SetPrecisionForUnitType(unitType UnitType, precision int)
- func (c *UnitConfig) UnmarshalJSON(data []byte) error
- type UnitConverter
- type UnitDetector
- type UnitMatch
- type UnitPattern
- type UnitPatterns
- type UnitProcessor
- func (p *UnitProcessor) GetConfig() *UnitConfig
- func (p *UnitProcessor) IsEnabled() bool
- func (p *UnitProcessor) ProcessComments(code string, language string) string
- func (p *UnitProcessor) ProcessText(text string, isCode bool, language string) string
- func (p *UnitProcessor) SetConfig(config *UnitConfig)
- func (p *UnitProcessor) SetEnabled(enabled bool)
- type UnitType
- type WordConfig
- type WordType
Constants ¶
This section is empty.
Variables ¶
var SmartQuotesMap = map[string]string{
"\u201C": "\"",
"\u201D": "\"",
"\u2018": "'",
"\u2019": "'",
"\u2013": "-",
"\u2014": "-",
}
SmartQuotesMap holds mappings for smart quotes and em-dashes to their normal equivalents
Functions ¶
func CreateExampleUserConfig ¶ added in v0.0.14
func CreateExampleUserConfig() error
CreateExampleUserConfig creates an example user configuration file with comments
func CreateUserConfigDirectory ¶ added in v0.0.14
func CreateUserConfigDirectory() error
CreateUserConfigDirectory creates the user configuration directory if it doesn't exist
func CreateUserConfigurationTemplate ¶ added in v0.0.23
func CreateUserConfigurationTemplate() error
CreateUserConfigurationTemplate creates a template configuration file with examples
func ExtractMatchedWord ¶ added in v0.0.23
ExtractMatchedWord extracts the actual word from a regex match, handling different capture group scenarios
func ExtractUnitFromMatch ¶ added in v0.0.14
ExtractUnitFromMatch extracts the unit name from a regex match
func GetConfigStatus ¶ added in v0.0.14
GetConfigStatus returns information about the current configuration status
func GetUserConfigPath ¶ added in v0.0.14
GetUserConfigPath returns the path to the user's unit configuration file
func SaveContextualWordConfig ¶ added in v0.0.23
func SaveContextualWordConfig(config *ContextualWordConfig) error
SaveContextualWordConfig saves the configuration to file
func SaveUserConfig ¶ added in v0.0.14
func SaveUserConfig(config *UnitConfig) error
SaveUserConfig saves the configuration to the user's config file
func ValidateConfig ¶ added in v0.0.14
func ValidateConfig(config *UnitConfig) error
ValidateConfig validates the configuration and returns any errors
Types ¶
type BasicUnitConverter ¶ added in v0.0.14
type BasicUnitConverter struct {
// contains filtered or unexported fields
}
BasicUnitConverter implements the UnitConverter interface using martinlindhe/unit
func NewBasicUnitConverter ¶ added in v0.0.14
func NewBasicUnitConverter() *BasicUnitConverter
NewBasicUnitConverter creates a new BasicUnitConverter with default settings
func (*BasicUnitConverter) Convert ¶ added in v0.0.14
func (c *BasicUnitConverter) Convert(match UnitMatch) (ConversionResult, error)
Convert converts a unit match to metric equivalent
func (*BasicUnitConverter) GetPreferences ¶ added in v0.0.14
func (c *BasicUnitConverter) GetPreferences() ConversionPreferences
GetPreferences returns the current conversion preferences
func (*BasicUnitConverter) SetPrecision ¶ added in v0.0.14
func (c *BasicUnitConverter) SetPrecision(unitType UnitType, precision int)
SetPrecision sets the decimal precision for a specific unit type
func (*BasicUnitConverter) SetPreferences ¶ added in v0.0.14
func (c *BasicUnitConverter) SetPreferences(prefs ConversionPreferences)
SetPreferences sets the conversion preferences
type CodeBlock ¶
type CodeBlock struct {
Start int // Start position in original text
End int // End position in original text
Language string // Detected language (if any)
Content string // Raw content of the code block
IsCode bool // true if this is code, false if it's regular text
}
CodeBlock represents a detected code block in text
type CommentBlock ¶
type CommentBlock struct {
Start int // Start position in code
End int // End position in code
Content string // Comment text
}
CommentBlock represents a comment within code
type ContextAwareWordDetector ¶ added in v0.0.23
type ContextAwareWordDetector struct {
// contains filtered or unexported fields
}
ContextAwareWordDetector implements contextual word detection with confidence scoring
func NewContextAwareWordDetector ¶ added in v0.0.23
func NewContextAwareWordDetector() *ContextAwareWordDetector
NewContextAwareWordDetector creates a new contextual word detector
func NewContextAwareWordDetectorWithConfig ¶ added in v0.0.23
func NewContextAwareWordDetectorWithConfig(config *ContextualWordConfig) *ContextAwareWordDetector
NewContextAwareWordDetectorWithConfig creates a new contextual word detector with specific configuration
func (*ContextAwareWordDetector) DetectWords ¶ added in v0.0.23
func (d *ContextAwareWordDetector) DetectWords(text string) []ContextualWordMatch
DetectWords finds contextual words in the given text and returns matches with confidence scores
func (*ContextAwareWordDetector) GetConfig ¶ added in v0.0.23
func (d *ContextAwareWordDetector) GetConfig() *ContextualWordConfig
GetConfig returns the current configuration (backward compatibility)
func (*ContextAwareWordDetector) GetConfiguration ¶ added in v0.0.23
func (d *ContextAwareWordDetector) GetConfiguration() *ContextualWordConfig
GetConfiguration returns the current configuration
func (*ContextAwareWordDetector) IsEnabled ¶ added in v0.0.23
func (d *ContextAwareWordDetector) IsEnabled() bool
IsEnabled returns whether contextual word detection is currently enabled
func (*ContextAwareWordDetector) SetConfig ¶ added in v0.0.23
func (d *ContextAwareWordDetector) SetConfig(config *ContextualWordConfig)
SetConfig updates the detector with new configuration (backward compatibility)
func (*ContextAwareWordDetector) SetEnabled ¶ added in v0.0.23
func (d *ContextAwareWordDetector) SetEnabled(enabled bool)
SetEnabled enables or disables contextual word detection
func (*ContextAwareWordDetector) SetMinConfidence ¶ added in v0.0.23
func (d *ContextAwareWordDetector) SetMinConfidence(confidence float64)
SetMinConfidence sets the minimum confidence threshold for matches
func (*ContextAwareWordDetector) SupportedWords ¶ added in v0.0.23
func (d *ContextAwareWordDetector) SupportedWords() []string
SupportedWords returns a list of words that support contextual conversion
func (*ContextAwareWordDetector) UpdateConfiguration ¶ added in v0.0.23
func (d *ContextAwareWordDetector) UpdateConfiguration(config *ContextualWordConfig)
UpdateConfiguration updates the detector with new configuration
type ContextualMapping ¶ added in v0.0.23
type ContextualMapping struct {
BaseWord string `json:"baseWord"` // The base American word (e.g., "license")
NounReplacement string `json:"nounReplacement"` // British spelling when used as noun (e.g., "licence")
VerbReplacement string `json:"verbReplacement"` // British spelling when used as verb (e.g., "license")
Confidence map[string]float64 `json:"confidence"` // Confidence overrides for different contexts
}
ContextualMapping represents a word that has different spellings based on context
type ContextualUnitDetector ¶ added in v0.0.14
type ContextualUnitDetector struct {
// contains filtered or unexported fields
}
ContextualUnitDetector implements contextual unit detection with confidence scoring
func NewContextualUnitDetector ¶ added in v0.0.14
func NewContextualUnitDetector() *ContextualUnitDetector
NewContextualUnitDetector creates a new contextual unit detector
func (*ContextualUnitDetector) DetectUnits ¶ added in v0.0.14
func (d *ContextualUnitDetector) DetectUnits(text string) []UnitMatch
DetectUnits detects units in text using contextual analysis and confidence scoring
func (*ContextualUnitDetector) SetMaxNumberDistance ¶ added in v0.0.14
func (d *ContextualUnitDetector) SetMaxNumberDistance(distance int)
SetMaxNumberDistance sets the maximum allowed distance between numbers and units
func (*ContextualUnitDetector) SetMinConfidence ¶ added in v0.0.14
func (d *ContextualUnitDetector) SetMinConfidence(confidence float64)
SetMinConfidence sets the minimum confidence threshold
func (*ContextualUnitDetector) SupportedUnits ¶ added in v0.0.14
func (d *ContextualUnitDetector) SupportedUnits() []UnitType
SupportedUnits returns the list of supported unit types
type ContextualWordConfig ¶ added in v0.0.23
type ContextualWordConfig struct {
// Global enable/disable flag
Enabled bool `json:"enabled"`
// Word configurations by base word
WordConfigs map[string]WordConfig `json:"wordConfigs"`
// Minimum confidence threshold for contextual detection (0.0 - 1.0)
MinConfidence float64 `json:"minConfidence"`
// Custom exclusion patterns (regex patterns to avoid conversion)
ExcludePatterns []string `json:"excludePatterns"`
// Conversion preferences
Preferences ContextualWordPreferences `json:"preferences"`
// Backward compatibility fields
SupportedWords []string `json:"-"` // Populated dynamically
CustomMappings map[string]ContextualMapping `json:"-"` // Populated dynamically
}
ContextualWordConfig holds all configuration options for contextual word conversion
func GetDefaultContextualWordConfig ¶ added in v0.0.23
func GetDefaultContextualWordConfig() *ContextualWordConfig
GetDefaultContextualWordConfig returns the default configuration with sensible defaults
func GetUserConfigurationExample ¶ added in v0.0.23
func GetUserConfigurationExample() *ContextualWordConfig
GetUserConfigurationExample returns an example configuration for users
func LoadContextualWordConfig ¶ added in v0.0.23
func LoadContextualWordConfig() (*ContextualWordConfig, error)
LoadContextualWordConfig loads the contextual word configuration from file
func LoadContextualWordConfigWithDefaults ¶ added in v0.0.23
func LoadContextualWordConfigWithDefaults() (*ContextualWordConfig, error)
LoadContextualWordConfigWithDefaults loads configuration with fallback to defaults
func (*ContextualWordConfig) AddCustomWord ¶ added in v0.0.23
func (c *ContextualWordConfig) AddCustomWord(baseWord, nounForm, verbForm string)
AddCustomWord adds a new word with contextual mappings to the configuration
func (*ContextualWordConfig) AddExclusionPattern ¶ added in v0.0.23
func (c *ContextualWordConfig) AddExclusionPattern(pattern string)
AddExclusionPattern adds a new exclusion pattern to the configuration
func (*ContextualWordConfig) DisableWord ¶ added in v0.0.23
func (c *ContextualWordConfig) DisableWord(baseWord string)
DisableWord disables contextual conversion for a specific word
func (*ContextualWordConfig) EnableWord ¶ added in v0.0.23
func (c *ContextualWordConfig) EnableWord(baseWord string)
EnableWord enables contextual conversion for a specific word
func (*ContextualWordConfig) GetMappingForWord ¶ added in v0.0.23
func (c *ContextualWordConfig) GetMappingForWord(word string) (ContextualMapping, bool)
GetMappingForWord returns the contextual mapping for a specific word in old format
func (*ContextualWordConfig) GetSupportedWords ¶ added in v0.0.23
func (c *ContextualWordConfig) GetSupportedWords() []string
GetSupportedWords returns a list of all enabled words for contextual conversion
func (*ContextualWordConfig) GetWordConfig ¶ added in v0.0.23
func (c *ContextualWordConfig) GetWordConfig(word string) (WordConfig, bool)
GetWordConfig returns the configuration for a specific word
func (*ContextualWordConfig) IsWordSupported ¶ added in v0.0.23
func (c *ContextualWordConfig) IsWordSupported(word string) bool
IsWordSupported checks if a word is enabled for contextual conversion
func (*ContextualWordConfig) RemoveCustomWord ¶ added in v0.0.23
func (c *ContextualWordConfig) RemoveCustomWord(baseWord string)
RemoveCustomWord removes a word from contextual conversion
func (*ContextualWordConfig) RemoveExclusionPattern ¶ added in v0.0.23
func (c *ContextualWordConfig) RemoveExclusionPattern(pattern string)
RemoveExclusionPattern removes an exclusion pattern from the configuration
type ContextualWordDetector ¶ added in v0.0.23
type ContextualWordDetector interface {
DetectWords(text string) []ContextualWordMatch
SupportedWords() []string
SetMinConfidence(confidence float64)
SetEnabled(enabled bool)
IsEnabled() bool
}
ContextualWordDetector interface defines the contract for contextual word detection
type ContextualWordMatch ¶ added in v0.0.23
type ContextualWordMatch struct {
Start int // Start position in text
End int // End position in text
OriginalWord string // The original word found
WordType WordType // Detected grammatical role
Replacement string // The contextually appropriate replacement
Confidence float64 // Confidence score for this match (0.0-1.0)
Context string // Surrounding context used for detection
BaseWord string // The base word this match relates to
}
ContextualWordMatch represents a detected word that needs contextual conversion
type ContextualWordPattern ¶ added in v0.0.23
type ContextualWordPattern struct {
Pattern *regexp.Regexp // Regex pattern to match the word in context
WordType WordType // The grammatical role this pattern detects
BaseWord string // The base word this pattern applies to (e.g., "license")
Replacement string // The appropriate spelling for this context (e.g., "licence" for noun)
Confidence float64 // Base confidence for this pattern (0.0-1.0)
Description string // Human-readable description of this pattern
}
ContextualWordPattern represents a regex pattern for detecting words in specific grammatical contexts
type ContextualWordPatterns ¶ added in v0.0.23
type ContextualWordPatterns struct {
// Word configurations by base word
WordConfigs map[string]WordConfig
// Generated patterns by base word
GeneratedPatterns map[string][]ContextualWordPattern
// Exclusion patterns for ambiguous or problematic contexts
ExclusionPatterns []*regexp.Regexp
// General pattern templates
GeneralPatterns []GeneralPattern
}
ContextualWordPatterns holds all the patterns and configuration for contextual word detection
func NewContextualWordPatterns ¶ added in v0.0.23
func NewContextualWordPatterns() *ContextualWordPatterns
NewContextualWordPatterns creates and initialises the contextual word detection system
func (*ContextualWordPatterns) AddWordConfig ¶ added in v0.0.23
func (p *ContextualWordPatterns) AddWordConfig(word string, config WordConfig)
AddWordConfig adds or updates a word configuration
func (*ContextualWordPatterns) GetAllPatterns ¶ added in v0.0.23
func (p *ContextualWordPatterns) GetAllPatterns() map[string][]ContextualWordPattern
GetAllPatterns returns all contextual word patterns grouped by base word
func (*ContextualWordPatterns) GetPatternsForWord ¶ added in v0.0.23
func (p *ContextualWordPatterns) GetPatternsForWord(baseWord string) []ContextualWordPattern
GetPatternsForWord returns all patterns for a specific base word
func (*ContextualWordPatterns) GetSupportedWords ¶ added in v0.0.23
func (p *ContextualWordPatterns) GetSupportedWords() []string
GetSupportedWords returns the list of words that support contextual conversion
func (*ContextualWordPatterns) GetWordConfig ¶ added in v0.0.23
func (p *ContextualWordPatterns) GetWordConfig(word string) (WordConfig, bool)
GetWordConfig returns the configuration for a specific word
func (*ContextualWordPatterns) IsExcluded ¶ added in v0.0.23
func (p *ContextualWordPatterns) IsExcluded(text string) bool
IsExcluded checks if the given text matches any exclusion pattern
type ContextualWordPreferences ¶ added in v0.0.23
type ContextualWordPreferences struct {
// Whether to prefer noun conversion when context is ambiguous
PreferNounOnAmbiguity bool `json:"preferNounOnAmbiguity"`
// Whether to fall back to regular dictionary when contextual conversion fails
FallbackToDictionary bool `json:"fallbackToDictionary"`
// Whether to show warnings for ambiguous contexts
ShowAmbiguityWarnings bool `json:"showAmbiguityWarnings"`
// Case sensitivity for pattern matching
CaseSensitive bool `json:"caseSensitive"`
// Whether to convert within quoted strings
ConvertQuotedText bool `json:"convertQuotedText"`
}
ContextualWordPreferences holds user preferences for contextual word conversion
type ConversionPreferences ¶ added in v0.0.14
type ConversionPreferences struct {
PreferWholeNumbers bool
MaxDecimalPlaces int
UseLocalizedUnits bool
TemperatureFormat string // "°C" or "degrees Celsius"
UseSpaceBetweenValueAndUnit bool // true: "5 kg", false: "5kg"
RoundingThreshold float64 // threshold for considering a value "close to whole" (default: 0.05)
}
ConversionPreferences holds user preferences for unit conversion
type ConversionResult ¶ added in v0.0.14
type ConversionResult struct {
MetricValue float64
MetricUnit string
Formatted string
Confidence float64
}
ConversionResult represents the result of a unit conversion
type Converter ¶
type Converter struct {
// contains filtered or unexported fields
}
Converter provides methods to convert between American and British English
func NewConverter ¶
NewConverter creates a new Converter instance
func (*Converter) ConvertToBritish ¶
ConvertToBritish converts American English text to British English
func (*Converter) ConvertToBritishSimple ¶
ConvertToBritishSimple converts text without code-awareness (for internal use)
func (*Converter) DetectCodeBlocks ¶
DetectCodeBlocks detects and extracts code blocks from mixed text
func (*Converter) ExtractComments ¶
func (c *Converter) ExtractComments(code, language string) []CommentBlock
ExtractComments extracts comment text from code using Chroma
func (*Converter) GetAmericanToBritishDictionary ¶
GetAmericanToBritishDictionary returns the American to British dictionary
func (*Converter) GetContextualWordDetector ¶ added in v0.0.23
func (c *Converter) GetContextualWordDetector() ContextualWordDetector
GetContextualWordDetector returns the contextual word detector instance
func (*Converter) GetUnitProcessor ¶ added in v0.0.14
func (c *Converter) GetUnitProcessor() *UnitProcessor
GetUnitProcessor returns the unit processor instance
func (*Converter) IsContextualWordDetectionEnabled ¶ added in v0.0.23
IsContextualWordDetectionEnabled returns whether contextual word detection is enabled
func (*Converter) ProcessCodeAware ¶
ProcessCodeAware processes text with code-awareness
func (*Converter) SetContextualWordDetectionEnabled ¶ added in v0.0.23
SetContextualWordDetectionEnabled enables or disables contextual word detection
func (*Converter) SetUnitProcessingEnabled ¶ added in v0.0.14
SetUnitProcessingEnabled enables or disables unit processing
type DetectionConfig ¶ added in v0.0.14
type DetectionConfig struct {
// Minimum confidence threshold for unit detection (0.0 - 1.0)
MinConfidence float64 `json:"minConfidence"`
// Maximum distance between number and unit (in words)
MaxNumberDistance int `json:"maxNumberDistance"`
// Whether to detect compound units (e.g., "6-foot")
DetectCompoundUnits bool `json:"detectCompoundUnits"`
// Whether to detect written numbers (e.g., "five feet")
DetectWrittenNumbers bool `json:"detectWrittenNumbers"`
}
DetectionConfig holds configuration for unit detection
type Dictionaries ¶
Dictionaries holds the mapping for American to British English spellings
func LoadDictionaries ¶
func LoadDictionaries() (*Dictionaries, error)
LoadDictionaries loads the American to British spelling dictionary from the embedded JSON file and merges it with the user's custom dictionary
type GeneralPattern ¶ added in v0.0.23
type GeneralPattern struct {
Name string // Pattern identifier
Template string // Pattern template with {WORD} placeholder
TargetType WordType // The grammatical role this pattern detects
Confidence float64 // Base confidence for this pattern (0.0-1.0)
}
GeneralPattern represents a reusable pattern template
type SentenceAwareConverter ¶ added in v0.0.23
type SentenceAwareConverter struct {
// contains filtered or unexported fields
}
SentenceAwareConverter enhances text conversion by processing text sentence by sentence This provides better context boundaries for contextual word detection
func NewSentenceAwareConverter ¶ added in v0.0.23
func NewSentenceAwareConverter() (*SentenceAwareConverter, error)
NewSentenceAwareConverter creates a new sentence-aware converter
func (*SentenceAwareConverter) ConvertToBritishSimple ¶ added in v0.0.23
func (sac *SentenceAwareConverter) ConvertToBritishSimple(text string, normaliseSmartQuotes bool) string
ConvertToBritishSimple delegates to the underlying converter for backwards compatibility
func (*SentenceAwareConverter) ConvertToBritishWithSentenceAwareness ¶ added in v0.0.23
func (sac *SentenceAwareConverter) ConvertToBritishWithSentenceAwareness(text string, normaliseSmartQuotes bool) string
ConvertToBritishWithSentenceAwareness converts text using sentence-level contextual analysis This provides better accuracy for longer texts with multiple contextual words
func (*SentenceAwareConverter) GetContextualWordDetector ¶ added in v0.0.23
func (sac *SentenceAwareConverter) GetContextualWordDetector() ContextualWordDetector
GetContextualWordDetector returns the contextual word detector
func (*SentenceAwareConverter) GetConverter ¶ added in v0.0.23
func (sac *SentenceAwareConverter) GetConverter() *Converter
GetConverter returns the underlying converter for advanced usage
func (*SentenceAwareConverter) IsContextualWordDetectionEnabled ¶ added in v0.0.23
func (sac *SentenceAwareConverter) IsContextualWordDetectionEnabled() bool
IsContextualWordDetectionEnabled checks if contextual word detection is enabled
func (*SentenceAwareConverter) SetContextualWordDetectionEnabled ¶ added in v0.0.23
func (sac *SentenceAwareConverter) SetContextualWordDetectionEnabled(enabled bool)
SetContextualWordDetectionEnabled enables or disables contextual word detection
type TextPart ¶
type TextPart struct {
Content string
IsCode bool
Language string
FenceType string // "“`" or "~~~" for fenced code blocks
}
TextPart represents a part of text that can be code or regular text
type TextSegment ¶
TextSegment represents a segment of text that can be either code or regular text
type UnitConfig ¶ added in v0.0.14
type UnitConfig struct {
// Global enable/disable flag
Enabled bool `json:"enabled"`
// Unit type specific settings
EnabledUnitTypes []UnitType `json:"enabledUnitTypes"`
// Precision settings for each unit type
Precision map[string]int `json:"precision"`
// Custom unit mappings (American -> British)
CustomMappings map[string]string `json:"customMappings"`
// Patterns to exclude from conversion (regex patterns)
ExcludePatterns []string `json:"excludePatterns"`
// Conversion preferences
Preferences ConversionPreferences `json:"preferences"`
// Detection settings
Detection DetectionConfig `json:"detection"`
}
UnitConfig holds all configuration options for unit conversion
func GetDefaultUnitConfig ¶ added in v0.0.14
func GetDefaultUnitConfig() *UnitConfig
GetDefaultUnitConfig returns the default configuration with sensible defaults
func LoadConfigWithDefaults ¶ added in v0.0.14
func LoadConfigWithDefaults() (*UnitConfig, error)
LoadConfigWithDefaults loads user configuration and merges it with defaults This is the main function that should be used to get the effective configuration
func LoadUserConfig ¶ added in v0.0.14
func LoadUserConfig() (*UnitConfig, error)
LoadUserConfig loads the user's unit configuration file Returns the default configuration if the file doesn't exist
func (*UnitConfig) Clone ¶ added in v0.0.14
func (c *UnitConfig) Clone() *UnitConfig
Clone creates a deep copy of the configuration
func (*UnitConfig) GetPrecisionForUnitType ¶ added in v0.0.14
func (c *UnitConfig) GetPrecisionForUnitType(unitType UnitType) int
GetPrecisionForUnitType returns the precision setting for a unit type
func (*UnitConfig) IsUnitTypeEnabled ¶ added in v0.0.14
func (c *UnitConfig) IsUnitTypeEnabled(unitType UnitType) bool
IsUnitTypeEnabled checks if a specific unit type is enabled in the configuration
func (*UnitConfig) MarshalJSON ¶ added in v0.0.14
func (c *UnitConfig) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling for UnitConfig
func (*UnitConfig) Merge ¶ added in v0.0.14
func (c *UnitConfig) Merge(other *UnitConfig)
Merge merges another configuration into this one, with the other config taking precedence
func (*UnitConfig) SetPrecisionForUnitType ¶ added in v0.0.14
func (c *UnitConfig) SetPrecisionForUnitType(unitType UnitType, precision int)
SetPrecisionForUnitType sets the precision for a specific unit type
func (*UnitConfig) UnmarshalJSON ¶ added in v0.0.14
func (c *UnitConfig) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling for UnitConfig
type UnitConverter ¶ added in v0.0.14
type UnitConverter interface {
Convert(match UnitMatch) (ConversionResult, error)
SetPrecision(unitType UnitType, precision int)
SetPreferences(prefs ConversionPreferences)
}
UnitConverter interface defines the contract for unit conversion
type UnitDetector ¶ added in v0.0.14
UnitDetector interface defines the contract for unit detection
type UnitMatch ¶ added in v0.0.14
type UnitMatch struct {
Start int
End int
Value float64
Unit string
UnitType UnitType
Context string
Confidence float64
IsCompound bool // true if this is a compound unit like "6-foot"
}
UnitMatch represents a detected unit in text
type UnitPattern ¶ added in v0.0.14
type UnitPattern struct {
Pattern *regexp.Regexp
UnitType UnitType
UnitNames []string // Possible unit names this pattern can match
Confidence float64 // Base confidence for this pattern
}
UnitPattern represents a regex pattern for detecting units
type UnitPatterns ¶ added in v0.0.14
type UnitPatterns struct {
// Positive patterns for detecting measurements
LengthPatterns []UnitPattern
MassPatterns []UnitPattern
VolumePatterns []UnitPattern
TemperaturePatterns []UnitPattern
AreaPatterns []UnitPattern
// Negative patterns for excluding idiomatic usage
ExclusionPatterns []*regexp.Regexp
}
UnitPatterns holds all the regex patterns for unit detection
func NewUnitPatterns ¶ added in v0.0.14
func NewUnitPatterns() *UnitPatterns
NewUnitPatterns creates and initializes all unit detection patterns
func (*UnitPatterns) GetAllPatterns ¶ added in v0.0.14
func (p *UnitPatterns) GetAllPatterns() map[UnitType][]UnitPattern
GetAllPatterns returns all unit patterns grouped by type
func (*UnitPatterns) IsExcluded ¶ added in v0.0.14
func (p *UnitPatterns) IsExcluded(text string) bool
IsExcluded checks if the given text matches any exclusion pattern
type UnitProcessor ¶ added in v0.0.14
type UnitProcessor struct {
// contains filtered or unexported fields
}
UnitProcessor handles unit detection and conversion
func NewUnitProcessor ¶ added in v0.0.14
func NewUnitProcessor() *UnitProcessor
NewUnitProcessor creates a new UnitProcessor with default components
func NewUnitProcessorWithConfig ¶ added in v0.0.14
func NewUnitProcessorWithConfig(config *UnitConfig) *UnitProcessor
NewUnitProcessorWithConfig creates a new UnitProcessor with a specific configuration
func (*UnitProcessor) GetConfig ¶ added in v0.0.14
func (p *UnitProcessor) GetConfig() *UnitConfig
GetConfig returns the current configuration
func (*UnitProcessor) IsEnabled ¶ added in v0.0.14
func (p *UnitProcessor) IsEnabled() bool
IsEnabled returns whether unit processing is enabled
func (*UnitProcessor) ProcessComments ¶ added in v0.0.14
func (p *UnitProcessor) ProcessComments(code string, language string) string
ProcessComments processes only comments within code for unit conversion
func (*UnitProcessor) ProcessText ¶ added in v0.0.14
func (p *UnitProcessor) ProcessText(text string, isCode bool, language string) string
ProcessText processes text for unit conversion
func (*UnitProcessor) SetConfig ¶ added in v0.0.14
func (p *UnitProcessor) SetConfig(config *UnitConfig)
SetConfig sets a new configuration
func (*UnitProcessor) SetEnabled ¶ added in v0.0.14
func (p *UnitProcessor) SetEnabled(enabled bool)
SetEnabled enables or disables unit processing
type UnitType ¶ added in v0.0.14
type UnitType int
UnitType represents different categories of units
type WordConfig ¶ added in v0.0.23
type WordConfig struct {
Noun string `json:"noun"` // British spelling when used as noun
Verb string `json:"verb"` // British spelling when used as verb
Enabled bool `json:"enabled"` // Whether this word pair is enabled
}
WordConfig represents the configuration for a contextual word pair