关于英语查询 - 请求帮助

发布于 2024-08-22 18:24:17 字数 2926 浏览 4 评论 0原文

我在印度塔塔研究开发设计中心担任研究员。我正在探索可用的数据库自然语言接口。在探索 MS English Query 时,我发现某些类型的关系没有给出适当的答案。

我们的架构如下所示:

Schema: 
Customer ( customer_id , customer_name, customer_address) 
Transaction ( transaction_id , customer_id_1, customer_id_2, amount) 

CUSTOMER 
cuctomer_id                customer_name        customer_address 
1                        John                        abc 
2                        Rohit                        pqr 
3                        Mark                        xyz 

TRANSACTION 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
2                        1                        3                        300 
3                        2                        1                        300 

这里,customer_id_1 和 customer_id_2 引用 Customer.customer_id。 一个表的两个以上属性引用另一个表中的相同主键属性。

查询:“给我约翰和罗希特之间的所有交易”

我们创建的实体是客户和交易;对于给定的英语查询,客户和交易之间建立了以下关系 -

Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: between Customer(customer_id_1) 
Preposition Clause: and Customer_1(customer_id_2) 

这里我们定义了客户的两种不同角色(通过2个连接路径-customer_id_1和customer_id_2)

我们期望的输出是trasaction_id为1和3的交易,但它是连接仅在 customer_id_1 上,结果为

Expected Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
3                        2                        1                        300 

Actual Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
2                        1                        3                        300 

发生这种情况是因为 default 和 and 之间的歧义,并且我们在介词子句中定义。

我们还尝试创建另一个关系

1) 
Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: by Customer(customer_id_1) 
Preposition Clause: to Customer_1(customer_id_2) 
2) 
Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: by Customer(customer_id_2) 
Preposition Clause: to Customer_1(customer_id_1) 

我们期望的输出是 trasaction_id 为 1 和 3 的交易,这里它需要 join on customer_id_1 和 customer_id_2, 但只使用了关系 1,而不是同时使用了 1 和 2,因此输出如下所示

Expected Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
3                        2                        1                        300 

Actual Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 

是否有一种解决方法可以创建关系,使 MSEQ 能够理解上述查询? 希望有人通过建议一些适当的解决方案来帮助我们。

I work as a researcher at Tata Research Development and Design Centre, India . I am exploring the available Natural Language Interfaces for database.While exploring MS English Query, I found that certain type of relationship does not give appropriate answer.

Our schema looks like as shown below:

Schema: 
Customer ( customer_id , customer_name, customer_address) 
Transaction ( transaction_id , customer_id_1, customer_id_2, amount) 

CUSTOMER 
cuctomer_id                customer_name        customer_address 
1                        John                        abc 
2                        Rohit                        pqr 
3                        Mark                        xyz 

TRANSACTION 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
2                        1                        3                        300 
3                        2                        1                        300 

Here, customer_id_1 and customer_id_2 references to Customer.customer_id.
More than two attributes of a table refers to same primary key attribute in another table.

Query : “Give me all transactions between John and Rohit”

The entities we made were Customer and transaction; for the given English query,following relationship was made between customers and transactions-

Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: between Customer(customer_id_1) 
Preposition Clause: and Customer_1(customer_id_2) 

Here we defined two different roles of customers(through 2 join path-customer_id_1 and customer_id_2)

The output we expect was transactions with trasaction_id as 1 and 3, but it was joining on customer_id_1 only and gave result as

Expected Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
3                        2                        1                        300 

Actual Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
2                        1                        3                        300 

This is happening because of ambiguity between default and and and we defined in preposition clause..

We also tried to create another relationship

1) 
Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: by Customer(customer_id_1) 
Preposition Clause: to Customer_1(customer_id_2) 
2) 
Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: by Customer(customer_id_2) 
Preposition Clause: to Customer_1(customer_id_1) 

The output we expect was transactions with trasaction_id as 1 and 3, here It took join on both customer_id_1 andcustomer_id_2,
But only relationship 1 was used and not both 1 and 2, so output was as follows

Expected Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
3                        2                        1                        300 

Actual Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 

Is there a work around for creating relationships that would make possible the above query to be understood by MSEQ?
Hope someone help us by suggesting some appropriate solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静赏你的温柔 2024-08-29 18:24:17

我看不懂你写的这么长的内容。如果您可以提供您所编写的确切查询,那就有意义了。不管怎样,尝试下面的查询,它会起作用。

SELECT [Transaction_Id]
      ,[Customer_Id_1]
      ,[Customer_Id_2]
      ,[Amount]
  FROM [TEST].[dbo].[Transaction] WHERE ((Customer_Id_1 = 1 AND Customer_Id_2 = 2)OR(Customer_Id_1 = 2 AND Customer_Id_2 = 1))

I couldn't understand what you wrote in length. It would make sense if you could provide what exact query you had written. Anyway, try the following query, it will work.

SELECT [Transaction_Id]
      ,[Customer_Id_1]
      ,[Customer_Id_2]
      ,[Amount]
  FROM [TEST].[dbo].[Transaction] WHERE ((Customer_Id_1 = 1 AND Customer_Id_2 = 2)OR(Customer_Id_1 = 2 AND Customer_Id_2 = 1))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文