0

我想从链接tatoebaarchive中的转储文件中在我的本地主机中创建一个离线句子词典数据库。从代码中可以看出,包含诸如、、之类的语言以及该语言中的句子;并将句子映射到翻译的平行句子。tatoeba.orgsentences.csvidsengfracmnturlinks.csvids

我想在一种语言中搜索一个单词,比如说eng,并列出成对的搜索单词的句子和它的翻译句子。例如,我在英语 (eng) 中搜索“美”,并在法语 (fra) 中将它们与平行句一起列出。

`sentences.csv` has three columns: `id` `language`  `text`
`links.csv` has two columns: `sentenceId`   `translatedId`

我可以分三步造一个平行句。

1)SELECT id FROM sentences WHERE text LIKE('%she is a rare beauty_%') AND language='eng'

       +-------+
       | id    |
       +-------+
       | 21687 |
       +-------+

2)SELECT translatedId FROM links WHERE sentenceId='21687'

      +--------------+
      | translatedId |
      +--------------+
      |       184559 |
      |       517365 |
      |       550067 |
      |      2238371 |
      |      2238372 |
      +--------------+

3)SELECT text FROM sentences WHERE (id ='550067' AND language='fra') OR id ='21687'

      +------------------------------------------+
      | text                                     |
      +------------------------------------------+
      | It is true she is a rare beauty.         |
      | C'est vrai, elle est d'une rare beauté.  |
      +------------------------------------------+

如何将三个查询合并为一个线性查询以获得第三步结果?

4

1 回答 1

0

不完全是我想要的,但这可以达到目的

  SELECT `sentences`.* FROM 
  `sentences` JOIN 
  `links` ON `id` = `translatedId` 
  WHERE `sentenceId` = (SELECT id FROM sentences WHERE text LIKE('%she is a rare beauty_%') AND language='eng' LIMIT 1);

结果是

  +---------+----------+-------------------------------------------------+
  | id      | language | text                                            |
  +---------+----------+-------------------------------------------------+
  |  184559 | jpn      | 確かに彼女は絶世の美人です。                    |
  |  517365 | deu      | Es ist wahr, sie ist eine seltene Schönheit.    |
  |  550067 | fra      | C'est vrai, elle est d'une rare beauté.         |
  | 2238371 | ber      | S tidet, drusit tsednan ay icebḥen am nettat.   |
  | 2238372 | ber      | Ccbaḥa-nnes drus tin ay tt-yesɛan.              |
  +---------+----------+-------------------------------------------------+
于 2013-10-12T10:22:17.157 回答