Resolve cultivar from free-text input

resolve_cultivar(
  cultivar_input,
  crop,
  cultivar_db = get_cached_cultivars(crop),
  use_ai = TRUE,
  use_cache = TRUE
)

Arguments

cultivar_input

Character string. The cultivar description to resolve.

crop

Character string. The crop for which to resolve the cultivar.

cultivar_db

Data frame. The database of supported cultivars. This is typically retrieved using get_cached_cultivars(crop) or a data.frame with a "name" column to specify cultivar names.

use_ai

Logical. Whether to use AI fallback if no deterministic match is found

use_cache

Logical. Whether to use caching for AI responses.

Value

A list with fields: cultivar (resolved cultivar name or "unknown"), source (resolution method), raw_input (original input), and assumptions (any assumptions made during resolution).

Details

This function attempts to interpret a farmer's free-text description of a cultivar using an LLM. It returns a structured representation with the best matching cultivar. If the input cannot be resolved, it returns "unknown".

The function first checks for direct matches against a list of supported cultivars for the specified crop. If no deterministic match is found and AI fallback is enabled, it uses an LLM to attempt resolution. The output includes the resolved cultivar, the source of the resolution (direct match, AI, or unresolvable), the raw input, and any assumptions made during resolution.

The output is a list with the following fields:

list( cultivar = "cultivar_name" | "unknown", source = "direct_match" | "ai_resolution" | "unresolvable", raw_input = "farmer_input", assumptions = NULL )

Examples

if (FALSE) { # \dontrun{
# Resolve a cultivar with direct match
cultivar_db <- data.frame(name = c("scepter", "scout", "gregory"), stringsAsFactors = FALSE)
result <- resolve_cultivar("scepter", "wheat", cultivar_db, use_ai = FALSE)

# Resolve with AI fallback for unknown cultivar
result <- resolve_cultivar("some local variety", "wheat", cultivar_db, use_ai = TRUE)
} # }