我正在寻找一种优雅的方法来解析可能具有别名标记(例如“AKA”和“FKA”)的法庭案件标题。我需要检索别名类型以及以下标题。我已经蛮力解决了,但想看看还有什么其他选择。我喜欢 Linq 并尝试过 Sprache,但无法完全理解它。
Example caption:
JOHN SMITH AKA JOHN R SMITH FKA JOHNNY R SMITH
Desired output:
Alias Type Found: AKA
Alias Caption Found: JOHN R SMITH
Alias Type Found: FKA
Alias Caption Found: JOHNNY R SMITH
以下是到目前为止我在 LinqPad 中汇总的内容。
void Main()
{
var caption = "JOHN SMITH AKA JOHN R SMITH FKA JOHNNY R SMITH";
caption.Split().ParseAliases( (t,c)=>{
Console.WriteLine ("Alias Type Found: {0}",t);
Console.WriteLine ("Alias Caption Found: {0}",c);
});
}
public delegate void AliasRetrievedDelegate(string aliasType, string aliasCaption);
public static class ParserExtensions{
private static IEnumerable<string> aliasTypes = new[]{"AKA","FKA"};
public static void ParseAliases(this IEnumerable<string> tokens,
aliasRetrievedDelegate d,
int startIdx = 0){
// TODO
}
}