Class: Lutaml::Xsd::Errors::Suggesters::TypeNotFoundSuggester

Inherits:
ErrorSuggester
  • Object
show all
Defined in:
lib/lutaml/xsd/errors/suggesters/type_not_found_suggester.rb

Overview

Suggester for type not found errors

Suggests similar type names using fuzzy matching

Examples:

Using the suggester

class TypeNotFoundError < EnhancedError
  use_suggester TypeNotFoundSuggester
end

error = TypeNotFoundError.new(
  "Type 'CdeType' not found",
  context: {
    actual_value: "CdeType",
    repository: schema_repository
  }
)
error.suggestions # => [Suggestion(text: "CodeType", similarity: 0.88), ...]

Constant Summary collapse

DEFAULT_LIMIT =

Returns Maximum number of suggestions.

Returns:

  • (Integer)

    Maximum number of suggestions

5
DEFAULT_MIN_SIMILARITY =

Returns Minimum similarity threshold.

Returns:

  • (Float)

    Minimum similarity threshold

0.6

Instance Method Summary collapse

Instance Method Details

#generate_suggestions(error) ⇒ Array<Suggestion>

Generate suggestions for type not found errors

Parameters:

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lutaml/xsd/errors/suggesters/type_not_found_suggester.rb', line 38

def generate_suggestions(error)
  return [] unless can_suggest?(error)

  query = actual_value_from(error)
  return [] unless query

  repository = repository_from(error)
  return [] unless repository

  matcher = FuzzyMatcher.new(repository,
                             min_similarity: min_similarity)
  matcher.find_similar_types(query, limit: suggestion_limit)
end