blob: 8fd349154febc719fc82ff090f6c79f4befba17c [file] [log] [blame]
Ian Maxon857dc132015-09-25 17:13:19 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
icetindile8fd4cc2014-08-05 20:25:16 -070019drop dataverse fuzzyjoin if exists;
20
21create dataverse fuzzyjoin;
22
23use dataverse fuzzyjoin;
24
25create type DBLPType as open {
26 id: int32,
27 dblpid: string,
28 title: string,
29 authors: string,
30 misc: string
31}
32
33create dataset DBLP(DBLPType) primary key id;
34
35set import-private-functions 'true';
36
37//
38// -- - Stage 3 - --
39//
40for $paperLeft in dataset('DBLP')
41for $paperRight in dataset('DBLP')
42for $ridpair in
43 //
44 // -- - Stage 2 - --
45 //
46 for $paperLeft in dataset('DBLP')
47 let $lenLeft := len(counthashed-word-tokens($paperLeft.title))
48 let $tokensLeft :=
49 for $tokenUnranked in counthashed-word-tokens($paperLeft.title)
50 for $tokenRanked at $i in
51 //
52 // -- - Stage 1 - --
53 //
54 for $paper in dataset('DBLP')
55 for $token in counthashed-word-tokens($paper.title)
56 group by $tokenGroupped := $token with $paper
57 order by count($paper), $tokenGroupped
58 return $tokenGroupped
59 where $tokenUnranked = $tokenRanked
60 order by $i
61 return $i
62 for $prefixTokenLeft in subset-collection(
63 $tokensLeft,
64 0,
65 prefix-len-jaccard($lenLeft, .5f))
66
67 for $paperRight in dataset('DBLP')
68 let $lenRight := len(counthashed-word-tokens($paperRight.title))
69 let $tokensRight :=
70 for $tokenUnranked in counthashed-word-tokens($paperRight.title)
71 for $tokenRanked at $i in
72 //
73 // -- - Stage 1 - --
74 //
75 for $paper in dataset('DBLP')
76 for $token in counthashed-word-tokens($paper.title)
77 group by $tokenGroupped := $token with $paper
78 order by count($paper), $tokenGroupped
79 return $tokenGroupped
80 where $tokenUnranked = $tokenRanked
81 order by $i
82 return $i
83 for $prefixTokenRight in subset-collection(
84 $tokensRight,
85 0,
86 prefix-len-jaccard($lenRight, .5f))
87
88 where $prefixTokenLeft = $prefixTokenRight
89
90 let $sim := similarity-jaccard-prefix(
91 $lenLeft,
92 $tokensLeft,
93 $lenRight,
94 $tokensRight,
95 $prefixTokenLeft,
96 .5f)
97 where $sim >= .5f and $paperLeft.id < $paperRight.id
98 group by $idLeft := $paperLeft.id, $idRight := $paperRight.id with $sim
99 return {'idLeft': $idLeft, 'idRight': $idRight, 'sim': $sim[0]}
100
101where $ridpair.idLeft = $paperLeft.id and $ridpair.idRight = $paperRight.id
102order by $paperLeft.id, $paperRight.id
Ian Maxon857dc132015-09-25 17:13:19 -0700103return {'left': $paperLeft, 'right': $paperRight, 'sim': $ridpair.sim}