【发布时间】:2021-11-28 15:35:30
【问题描述】:
我已成功集成 Azure 认知搜索,并且通常按预期工作。现在,我被要求整合关键短语提取技能组。
我们已经创建了多合一键,更新了索引以包括语言检测和关键短语提取(关键短语需要文档上的语言代码),并且索引更新是成功的......或者我们相信.查看 Azure 控制台时,我看到所有已定义的技能集,属性存在于文档中,但这些字段中没有数据。
我的示例文档如下所示
public class SearchableDocument {
[SimpleField(IsKey = true, IsFilterable = true)]
public string Id { get; set; }
[SearchableField(IsFilterable = true)]
public string Text { get; set; }
[SimpleField]
public string[] KeyPhrases { get; set; }
[SimpleField]
public string LanguageCode { get; set; }
}
那么索引设置是这样的
public void CreateOrUpdateSkillsetAsync()
{
var serviceEndpoint = CreateServiceEndPoint();
var credential = new AzureKeyCredential(_cognitiveApiKey);
var languageDetectSkill = CreateLanguageDetectionSkill();
var keyPhraseSkill = CreateKeyPhraseExtractionSkill();
var skills = new List<SearchIndexerSkill>
{
languageDetectSkill,
keyPhraseSkill
};
var skillSetName = _cognitiveIndexName;
var skillSet = new SearchIndexerSkillset(skillSetName, skills);
skillSet.Description = _configProvider.GetCurrentEnvironmentName();
skillSet.CognitiveServicesAccount = new CognitiveServicesAccountKey(_cognitiveServiceAllInOneKey);
var client = new SearchIndexerClient(serviceEndpoint, credential);
client.CreateOrUpdateSkillset(skillSet);
}
private LanguageDetectionSkill CreateLanguageDetectionSkill()
{
var inputMappings = new List<InputFieldMappingEntry>();
inputMappings.Add(new InputFieldMappingEntry("text")
{
Source = "/document/Text",
});
var outputMappings = new List<OutputFieldMappingEntry>
{
new OutputFieldMappingEntry("languageCode")
{
TargetName = "LanguageCode"
}
};
var skill = new LanguageDetectionSkill(inputMappings, outputMappings)
{
Name = "Language Detection",
Description = "Detect language",
Context = "/document/*",
};
return skill;
}
private KeyPhraseExtractionSkill CreateKeyPhraseExtractionSkill()
{
var inputMappings = new List<InputFieldMappingEntry>();
inputMappings.Add(new InputFieldMappingEntry("text")
{
Source = "/document/Text",
});
inputMappings.Add(new InputFieldMappingEntry("languageCode")
{
Source = "/document/LanguageCode"
});
var outputMappings = new List<OutputFieldMappingEntry>
{
new OutputFieldMappingEntry("keyPhrases")
{
TargetName = "KeyPhrases"
}
};
var keyPhraseExtractionSkill = new KeyPhraseExtractionSkill(inputMappings, outputMappings)
{
Name = "KeyPhrase Extraction",
Description = "Extract the key phrases",
Context = "/document/*",
DefaultLanguageCode = KeyPhraseExtractionSkillLanguage.En,
};
return keyPhraseExtractionSkill;
}
在使用技能集更新索引后,我期待属性 LangaugeCode 和 KeyPhrases 会开始填写。但这不适用于新文档或现有文档。
【问题讨论】:
标签: azure azure-cognitive-search azure-cognitive-services