forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextSkill.cs
99 lines (92 loc) · 3.09 KB
/
TextSkill.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.SemanticKernel.SkillDefinition;
namespace Microsoft.SemanticKernel.CoreSkills;
/// <summary>
/// TextSkill provides a set of functions to manipulate strings.
/// </summary>
/// <example>
/// Usage: kernel.ImportSkill("text", new TextSkill());
///
/// Examples:
/// SKContext["input"] = " hello world "
/// {{text.trim $input}} => "hello world"
/// {{text.trimStart $input} => "hello world "
/// {{text.trimEnd $input} => " hello world"
/// SKContext["input"] = "hello world"
/// {{text.uppercase $input}} => "HELLO WORLD"
/// SKContext["input"] = "HELLO WORLD"
/// {{text.lowercase $input}} => "hello world"
/// </example>
public class TextSkill
{
/// <summary>
/// Trim whitespace from the start and end of a string.
/// </summary>
/// <example>
/// SKContext["input"] = " hello world "
/// {{text.trim $input}} => "hello world"
/// </example>
/// <param name="text"> The string to trim. </param>
/// <returns> The trimmed string. </returns>
[SKFunction("Trim whitespace from the start and end of a string.")]
public string Trim(string text)
{
return text.Trim();
}
/// <summary>
/// Trim whitespace from the start of a string.
/// </summary>
/// <example>
/// SKContext["input"] = " hello world "
/// {{text.trimStart $input} => "hello world "
/// </example>
/// <param name="text"> The string to trim. </param>
/// <returns> The trimmed string. </returns>
[SKFunction("Trim whitespace from the start of a string.")]
public string TrimStart(string text)
{
return text.TrimStart();
}
/// <summary>
/// Trim whitespace from the end of a string.
/// </summary>
/// <example>
/// SKContext["input"] = " hello world "
/// {{text.trimEnd $input} => " hello world"
/// </example>
/// <param name="text"> The string to trim. </param>
/// <returns> The trimmed string. </returns>
[SKFunction("Trim whitespace from the end of a string.")]
public string TrimEnd(string text)
{
return text.TrimEnd();
}
/// <summary>
/// Convert a string to uppercase.
/// </summary>
/// <example>
/// SKContext["input"] = "hello world"
/// {{text.uppercase $input}} => "HELLO WORLD"
/// </example>
/// <param name="text"> The string to convert. </param>
/// <returns> The converted string. </returns>
[SKFunction("Convert a string to uppercase.")]
public string Uppercase(string text)
{
return text.ToUpper(System.Globalization.CultureInfo.CurrentCulture);
}
/// <summary>
/// Convert a string to lowercase.
/// </summary>
/// <example>
/// SKContext["input"] = "HELLO WORLD"
/// {{text.lowercase $input}} => "hello world"
/// </example>
/// <param name="text"> The string to convert. </param>
/// <returns> The converted string. </returns>
[SKFunction("Convert a string to lowercase.")]
public string Lowercase(string text)
{
return text.ToLower(System.Globalization.CultureInfo.CurrentCulture);
}
}