gpt4 book ai didi

azure - 如何在 Azure 逻辑应用程序中按行解析文本?

转载 作者:行者123 更新时间:2023-12-03 06:52:47 28 4
gpt4 key购买 nike

我有一个逻辑应用程序,可以从表单提交中读取电子邮件。不幸的是,我只能访问电子邮件,而不能访问表单结果的存储位置,因此我当前将逻辑应用设置为提取电子邮件并将其转换为文本。

如果它只是一个字段,我认为我可以抓取所有字段,将其放入变量中并将其拆分以获得我需要的内容,但我不确定如何使用多行来执行此操作。

电子邮件始终采用以下格式:

---

日期:2022年8月18日

时间:09:30:00

请求者姓名:Robert Bobson

请求者电子邮件:[email protected]

请求者电话号码:800-867-5309

网站名称:公司名称

站点编号:123456789

---

我是否可以设置行索引,然后抓取该行上的所有内容,然后在将其分配给变量之前将其拆分?这是否需要正则表达式,或者逻辑应用中是否有解决方法或表达式可以处理此问题?

提前谢谢您!

最佳答案

您可以使用表达式来实现您的要求。

首先,尝试从给定电子邮件中删除多余的行。下面是我用来实现相同目的的表达式。

split(outputs('Compose'),'\n\n')

以上表达式的结果是: enter image description here

Am I able to set a line index and then grab everything on that line and then split it before assigning it to a variable?

是的,可以使用下面的表达式来实现

outputs('Compose_2')?[0] gives the Date 
outputs('Compose_2')?[1] gives the Time
...

结果:

enter image description here

或者,您可以将字符串转换为 Parsable Json,然后通过 Parse JSON Action 对其进行解析。下面是我的逻辑应用程序的流程

enter image description here

在上面的步骤中,我提取左侧和右侧的值并将它们存储到变量中。您可以使用切片或子字符串函数来提取值。

enter image description here

在下一步中,我将尝试通过解析 JSON 操作来解析值。

结果:

enter image description here

您可以在逻辑应用程序中使用以下代码 View 进行相同的测试

{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "Date: 08/18/2022\n\nTime: 09:30:00\n\nRequestor Name: Robert Bobson\n\nRequestor Email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bddfd2dffdded2d0cddcd3c4d3dcd0d893ded2d0" rel="noreferrer noopener nofollow">[email protected]</a>\n\nRequestor Phone Number: 800-867-5309\n\nSite Name: CompanyName\n\nSite Number: 123456789",
"runAfter": {},
"type": "Compose"
},
"Compose_2": {
"inputs": "@split(outputs('Compose'),'\n\n')",
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "Compose"
},
"Compose_3": {
"inputs": "@body('Parse_JSON')?['Site Name']",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Compose"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "length",
"type": "integer"
}
]
},
"runAfter": {
"Compose_2": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "Json",
"type": "string"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@concat('{',substring(variables('Json'),0,sub(length(variables('Json')),1)),'}')",
"schema": {
"properties": {
"Date": {
"type": "string"
},
"Requestor Email": {
"type": "string"
},
"Requestor Name": {
"type": "string"
},
"Requestor Phone Number": {
"type": "string"
},
"Site Name": {
"type": "string"
},
"Site Number": {
"type": "string"
},
"Time": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"Until": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Until": {
"actions": {
"Append_to_string_variable": {
"inputs": {
"name": "Json",
"value": "@{outputs('Current_Object')},"
},
"runAfter": {
"Current_Object": [
"Succeeded"
]
},
"type": "AppendToStringVariable"
},
"Current_Object": {
"inputs": "\"@{substring(outputs('Compose_2')?[variables('length')],0,indexOf(outputs('Compose_2')?[variables('length')],':'))}\":\"@{slice(outputs('Compose_2')?[variables('length')],add(indexOf(outputs('Compose_2')?[variables('length')],':'),2),length(outputs('Compose_2')?[variables('length')]))}\"",
"runAfter": {},
"type": "Compose"
},
"Increment_variable": {
"inputs": {
"name": "length",
"value": 1
},
"runAfter": {
"Append_to_string_variable": [
"Succeeded"
]
},
"type": "IncrementVariable"
}
},
"expression": "@equals(variables('length'), length(outputs('Compose_2')))",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {
"Initialize_variable_2": [
"Succeeded"
]
},
"type": "Until"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

关于azure - 如何在 Azure 逻辑应用程序中按行解析文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73405642/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com