blob: 8fd349154febc719fc82ff090f6c79f4befba17c [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
drop dataverse fuzzyjoin if exists;
create dataverse fuzzyjoin;
use dataverse fuzzyjoin;
create type DBLPType as open {
id: int32,
dblpid: string,
title: string,
authors: string,
misc: string
}
create dataset DBLP(DBLPType) primary key id;
set import-private-functions 'true';
//
// -- - Stage 3 - --
//
for $paperLeft in dataset('DBLP')
for $paperRight in dataset('DBLP')
for $ridpair in
//
// -- - Stage 2 - --
//
for $paperLeft in dataset('DBLP')
let $lenLeft := len(counthashed-word-tokens($paperLeft.title))
let $tokensLeft :=
for $tokenUnranked in counthashed-word-tokens($paperLeft.title)
for $tokenRanked at $i in
//
// -- - Stage 1 - --
//
for $paper in dataset('DBLP')
for $token in counthashed-word-tokens($paper.title)
group by $tokenGroupped := $token with $paper
order by count($paper), $tokenGroupped
return $tokenGroupped
where $tokenUnranked = $tokenRanked
order by $i
return $i
for $prefixTokenLeft in subset-collection(
$tokensLeft,
0,
prefix-len-jaccard($lenLeft, .5f))
for $paperRight in dataset('DBLP')
let $lenRight := len(counthashed-word-tokens($paperRight.title))
let $tokensRight :=
for $tokenUnranked in counthashed-word-tokens($paperRight.title)
for $tokenRanked at $i in
//
// -- - Stage 1 - --
//
for $paper in dataset('DBLP')
for $token in counthashed-word-tokens($paper.title)
group by $tokenGroupped := $token with $paper
order by count($paper), $tokenGroupped
return $tokenGroupped
where $tokenUnranked = $tokenRanked
order by $i
return $i
for $prefixTokenRight in subset-collection(
$tokensRight,
0,
prefix-len-jaccard($lenRight, .5f))
where $prefixTokenLeft = $prefixTokenRight
let $sim := similarity-jaccard-prefix(
$lenLeft,
$tokensLeft,
$lenRight,
$tokensRight,
$prefixTokenLeft,
.5f)
where $sim >= .5f and $paperLeft.id < $paperRight.id
group by $idLeft := $paperLeft.id, $idRight := $paperRight.id with $sim
return {'idLeft': $idLeft, 'idRight': $idRight, 'sim': $sim[0]}
where $ridpair.idLeft = $paperLeft.id and $ridpair.idRight = $paperRight.id
order by $paperLeft.id, $paperRight.id
return {'left': $paperLeft, 'right': $paperRight, 'sim': $ridpair.sim}