"String" (比较方法)
Details
- By default, the "String" comparison method considers two strings to be equivalent if they are identical.
- The distance metric and the corresponding tolerance can be set using the DistanceFunction and Tolerance option. EditDistance is the default distance function.
- The DistanceFunction is only used for nonzero Tolerance. Other compatible distance metrics include HammingDistance and DamerauLevenshteinDistance.
- Additionally, options for the distance metrics, like IgnoreCase, are also supported in the second argument of the AssessmentFunction.
- When multiple values in the answer key are within the tolerance range of an answer, the closest value is selected.
范例
打开所有单元 关闭所有单元基本范例 (3)
Create an AssessmentFunction for a string question:
stringaf = AssessmentFunction["Dog", "String"]stringaf["Dog"]stringaf["Dig"]Define assessment for a DNA sequence with tolerance:
dnatest = AssessmentFunction["AGGTCCCAAAA", Tolerance -> 2]Any sequence within an EditDistance of two is considered correct:
dnatest["AGGTTCCAAAT"]Set multiple answer keys with custom scores and infer the string method:
stringaf = AssessmentFunction[{"Dog" -> 2, "Cat" -> -2}]result = stringaf["Dog"]Get more details from the result:
result[{"Score", "AnswerCorrect"}]Scope (2)
Perform category assessment involving strings:
asmf = AssessmentFunction[{"Iguana" -> <|"Category" -> "Reptile", "Score" -> 1|>, "Moose" -> <|"Category" -> "Mammal", "Score" -> 1|>}]asmf["Moose" -> "Mammal"]Assess each element of a list separately:
assessment = AssessmentFunction[{"tall" -> 1, "big" -> 2, "giant" -> 3, "small" -> -1}, <|"ListAssessment" -> "SeparatelyScoreElements"|>][{"big", "small"}]assessment[All]Options (2)
stringAF = AssessmentFunction[{"Dog" -> 2, "Cat" -> -2}, Tolerance -> 1]stringAF["Doug"]stringAF["Drug"]Compute equivalent comparisons directly:
EditDistance["Doug", "Dog"]EditDistance["Drug", "Dog"]Using different distance metrics might produce different results:
AssessmentFunction["Doug", Tolerance -> 2, DistanceFunction -> EditDistance]["Dugo"]AssessmentFunction["Doug", Tolerance -> 2, DistanceFunction -> HammingDistance]["Dugo"]This is consistent with using the distance metrics directly:
EditDistance["Doug", "Dugo"]HammingDistance["Doug", "Dugo"]Applications (1)
Define a utility function to make BioSequenceComplement support DNA strings:
flipdna[str_] := BioSequenceComplement[BioSequence["DNA", str]]["SequenceString"]Create a QuestionObject for determining DNA complements allowing one mistake in each:
QuestionObject[
QuestionInterface["TextCompletion", <|
"Prompt" -> "Give the complementary genetic sequences:",
"Template" -> "ACTGG ``
GACTT ``"
|>
],
AssessmentFunction[{flipdna /@ {"ACTGG", "GACTT"}}, <|"ComparisonMethod" -> "String", "ListAssessment" -> "AllElementsOrdered"|>, Tolerance -> 1]
]Properties & Relations (1)
Possible Issues (2)
Some metrics only work when comparing strings with equal length:
AssessmentFunction["Dog", DistanceFunction -> HammingDistance]["Doug"]The "String" comparison method is based on distances, not patterns. Matching of string patterns is not supported:
AssessmentFunction["A*", "String"]["Apple"]Instead, specify StringMatchQ as a custom comparator:
AssessmentFunction["A*", StringMatchQ]["Apple"]参见
AssessmentFunction ▪ QuestionObject ▪ DistanceFunction
问题界面类型: ShortAnswer TextCompletion DragCompletion
比较方法: Expression Date