我有一个以下格式的数据列:
文本
Hello world
Hello
How are you today
I love stackoverflow
blah blah blahdy
Run Code Online (Sandbox Code Playgroud)
我想通过使用tau包的textcnt()函数来计算此数据集中每行的3克.但是,当我尝试它时,它给了我一个数字向量,其中包含整个列的ngrams.如何将此功能分别应用于我的数据中的每个观察?
我有一个接口来初始化数据,该数据将生成包含不同对象类型的列表:
public interface DataInitializer {
public void initializeData();
public ArrayList<> getData();
}
Run Code Online (Sandbox Code Playgroud)
当我实现这个抽象时,实现类的 getData() 方法将需要返回包含不同类型对象的 ArrayList,例如:
public ArrayList<Faculty> getData()
public ArrayList<Student> getData()
Run Code Online (Sandbox Code Playgroud)
如何在界面中考虑这种所需的灵活性?
我正在与Flurl一起使用需要基于证书的身份验证的API。我从这篇SO帖子中看到,向中添加证书WebRequestHandler并指示an HttpClient使用此处理程序很容易。
但是,使用Flurl对我来说还不太清楚。我已经尝试了以下三件事。
扩展DefaultHttpFactory
我首先怀疑我需要创建自己X509HttpFactory : DefaultHttpFactory的应用程序,该应用程序将创建处理程序并将其分配给HttpClient。但是,在查看源代码时,我注意到的构造函数CreateClient已经期望有一个处理程序。这个处理程序来自哪里?
使用DefaultHttpFactory创建客户端
WebRequestHandler handler = new WebRequestHandler();
handler.ClientCertificates.Add(myX509Cert);
var clientFactory = new DefaultHttpClientFactory();
FlurlClient fc = clientFactory.CreateClient(url, handler);
Run Code Online (Sandbox Code Playgroud)
无法编译,因为HttpClient无法转换为FlurlClient
使用ConfigureHttpClient
var clientFactory = new DefaultHttpClientFactory();
FlurlClient fc = new Url("foobar.com").ConfigureHttpClient(client => client = clientFactory
.CreateClient(url, handler));
Run Code Online (Sandbox Code Playgroud)
这似乎是最可行的选择,但是我不确定,因为委托是Action没有返回类型的。
问题
使用Flurl支持客户端证书认证的最佳/正确方法是什么?
我试图解码一些通过检索的JSON http.Get.但是,当我检查我初始化的结构时fmt.Println,它们总是空的.
我怀疑这是因为我的struct的结构与返回的JSON不一致,但我不确定如何解决它.一般来说,我不太确定解码器的工作原理.
这是JSON:
{
"response":[
{
"list": {
"category":"(noun)",
"synonyms":"histrion|player|thespian|role player|performer|performing artist"
}
},
{
"list": {
"category":"(noun)",
"synonyms":"doer|worker|person|individual|someone|somebody|mortal|soul"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所尝试的:
type SynonymResponse struct {
lists []SynonymList
}
type SynonymList struct {
category string
synonyms string
}
var synonyms SynonymResponse;
dec := json.NewDecoder(response.Body)
err := dec.Decode(&synonyms)
if err != nil {
log.Fatal(err)
}
fmt.Println(synonyms)
Run Code Online (Sandbox Code Playgroud)
编辑:Per @Leo的回答和@ JimB的提示,我的尝试有两个问题.下面是正确的结构集,尽管Leo指出,这将是空的:
type SynonymResponses struct {
resp []SynonymResponse
}
type SynonymResponse struct {
listo SynonymList
} …Run Code Online (Sandbox Code Playgroud) 我正在构建一个client-server socket模拟,C我TCP connection从客户端接受一个,然后客户端向我的服务器发送一条消息.我正在成功接收消息,然后我遍历我array的structs寻找字符串匹配
struct Mapping
{
char key[6];
char value[8];
} MapElement;
int main
{
char buf[BUFSIZE]; /* BUFSIZE 2048 */
int size = 4;
struct Mapping serverMap[size];
initialize_server_map(serverMap); /* This method works, so not displaying in SO */
/* ... socket stuff (this works as seen from print statements) */
recvlen = recv(rqst, buf, BUFSIZE, 0);
printf("The received length is %d\n", recvlen);
printf("The buf is: %s\n", buf);
if (recvlen …Run Code Online (Sandbox Code Playgroud)