@see https://github.com/louismullie/treat/blob/master/lib/treat/workers/extractors/tf_idf/native.rb#L12

 SMART l, Chisholm LOGA
178491
def log_term_frequency(document, term)
      count = document.term_count(term)
      if count > 0
        1 + log(count)
      else
        0
      end
    end
515225
private SmartForest<String[]> termStatus(SmartForest<String[]> branch, Term term) {
        String name = term.getName();
        SmartForest<String[]> sf = branch;
        for (int j = 0; j < name.length(); j++) {
            sf = sf.get(name.charAt(j));
            if (sf == null) {
                return null;
            }
        }
        return sf;
    }
1101390
def rlw_filter(name, location, size, unsize):
    
    arch = _meta_.arch
    if arch.startswith("i") and arch.endswith("86"):
        arch = "i486"
    (fname, flocation, fsize, funsize) = ([] for i in range(4))
    for n, l, s, u in zip(name, location, size, unsize):
        loc = l.split("/")
        if arch == loc[-1]:
            fname.append(n)
            flocation.append(l)
            fsize.append(s)
            funsize.append(u)
    return [fname, flocation, fsize, funsize]
806172
function Stash(nlz) {
  if (!(this instanceof Stash)) return new Stash(nlz);

  nlz = nlz || function(val) {return val};
  assert.equal(typeof nlz, 'function', 'linkstash: nlz should be a function');

  this._prev = null;
  this._next = null;
  this._nlz = nlz;

  return this;
}
780223
function parse_Array(blob, length, opts) {
	var ref = parse_Ref(blob, 6);
	/* TODO: fAlwaysCalc */
	switch(opts.biff) {
		case 2: blob.l ++; length -= 7; break;
		case 3: case 4: blob.l += 2; length -= 8; break;
		default: blob.l += 6; length -= 12;
	}
	return [ref, parse_ArrayParsedFormula(blob, length, opts, ref)];
}
640028
function (match, indexed_rule) {
        var token,
            lines,
            backup;

        if (this.options.backtrack_lexer) {
            // save context
            backup = {
                yylineno: this.yylineno,
                yylloc: {
                    first_line: this.yylloc.first_line,
                    last_line: this.last_line,
                    first_column: this.yylloc.first_column,
                    last_column: this.yylloc.last_column
                },
                yytext: this.yytext,
                match: this.match,
                matches: this.matches,
                matched: this.matched,
                yyleng: this.yyleng,
                offset: this.offset,
                _more: this._more,
                _input: this._input,
                yy: this.yy,
                conditionStack: this.conditionStack.slice(0),
                done: this.done
            };
            if (this.options.ranges) {
                backup.yylloc.range = this.yylloc.range.slice(0);
            }
        }

        lines = match[0].match(/(?:\r\n?|\n).*/g);
        if (lines) {
            this.yylineno += lines.length;
        }
        this.yylloc = {
            first_line: this.yylloc.last_line,
            last_line: this.yylineno + 1,
            first_column: this.yylloc.last_column,
            last_column: lines ?
                         lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
                         this.yylloc.last_column + match[0].length
        };
        this.yytext += match[0];
        this.match += match[0];
        this.matches = match;
        this.yyleng = this.yytext.length;
        if (this.options.ranges) {
            this.yylloc.range = [this.offset, this.offset += this.yyleng];
        }
        this._more = false;
        this._backtrack = false;
        this._input = this._input.slice(match[0].length);
        this.matched += match[0];
        token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
        if (this.done && this._input) {
            this.done = false;
        }
        if (token) {
            return token;
        } else if (this._backtrack) {
            // recover context
            for (var k in backup) {
                this[k] = backup[k];
            }
            return false; // rule action called reject() implying the next rule should be tested instead.
        }
        return false;
    }
1145706
function f_kalem_teklif_kontrol(_tahta_id, _kalem_id) {
        if (_tahta_id > 0) {
            return result.dbQ.sinter(result.kp.kalem.ssetTeklifleri(_kalem_id), result.kp.tahta.ssetTeklifleri(_tahta_id, true));
        } else {
            return [];
        }
    }
561349
function lintMethod (mtd, file, config, cb, configPath) {
	let runConfig = transformConfig(config);

	if (typeof cb !== 'function') {
		cb = function () {};
	}

	try {
		let results = sassLint[mtd](file, runConfig, configPath);

		if (mtd !== 'lintFiles') {
			if (!Array.isArray(results)) {
				results = [results];
			}
		}

		let data = {
			results,
			errorCount: sassLint.errorCount(results),
			warningCount: sassLint.warningCount(results)
		};

		cb(null, data);
	} catch (err) {
		cb(err);
	}
}
596054
function smartIndexOf(array, test) {
    var index = -1;
    if (!array || !test) return index;
    var length = array.length;
    if (!length) return index;
    while (++index < length) {
        if (test(array[index], index, array)) return index;
    }
    return -1;
}
980312
function TFIDF (ops) {
  const calculateScore = (x, i, resultset) => {
    const idf = Math.log((global.D + 1) / resultset.length);
    x.score = +x.match.reduce(
      (acc, cur) => acc + idf * +cur.split(':')[1], 0
    ).toFixed(2); // TODO: make precision an option
    return x
  };
  return ops
    .resultSet
    .map(calculateScore)
  // sort by score descending
    .sort((a, b) => b.score - a.score)
  // limit to n hits
    .slice(ops.offset, ops.limit)
}
218889
function rlnorm(meanlog, sdlog) {
      var rnorm;

      rnorm = normal.rnorm(meanlog, sdlog);

      return function() {
         return Math.exp(rnorm());
      };
   }
123914
function logMessage(fig, st, lns) {
  return lns.reduce((a, b) => a.concat(`  ${b}`), [`\n${fig} ${st}`]);
}
822896
function parse_NameParsedFormula(blob, length, opts, cce) {
	var target = blob.l + length;
	var rgce = parse_Rgce(blob, cce, opts);
	var rgcb;
	if(target !== blob.l) rgcb = parse_RgbExtra(blob, target - blob.l, rgce, opts);
	return [rgce, rgcb];
}
423011
private au.csiro.snorocket.core.model.AbstractLiteral transformLiteral(Literal l) {
        if(l instanceof au.csiro.ontology.model.DateLiteral) {
            return new DateLiteral(((au.csiro.ontology.model.DateLiteral) l).getValue());
        } else if(l instanceof au.csiro.ontology.model.DecimalLiteral) {
            return new DecimalLiteral(((au.csiro.ontology.model.DecimalLiteral) l).getValue());
        } else if(l instanceof au.csiro.ontology.model.IntegerLiteral) {
            return new IntegerLiteral(((au.csiro.ontology.model.IntegerLiteral) l).getValue());
        } else if(l instanceof au.csiro.ontology.model.StringLiteral) {
            return new StringLiteral(((au.csiro.ontology.model.StringLiteral) l).getValue());
        } else if(l instanceof au.csiro.ontology.model.FloatLiteral) {
            return new DecimalLiteral(new BigDecimal(((au.csiro.ontology.model.FloatLiteral) l).getValue()));
        } else {
            throw new RuntimeException("Unexpected AbstractLiteral "+l.getClass().getName());
        }
    }
54813
def _extract_multi_indexer_columns(self, header, index_names, col_names,
                                       passed_names=False):
        
        if len(header) < 2:
            return header[0], index_names, col_names, passed_names

        # the names are the tuples of the header that are not the index cols
        # 0 is the name of the index, assuming index_col is a list of column
        # numbers
        ic = self.index_col
        if ic is None:
            ic = []

        if not isinstance(ic, (list, tuple, np.ndarray)):
            ic = [ic]
        sic = set(ic)

        # clean the index_names
        index_names = header.pop(-1)
        index_names, names, index_col = _clean_index_names(index_names,
                                                           self.index_col,
                                                           self.unnamed_cols)

        # extract the columns
        field_count = len(header[0])

        def extract(r):
            return tuple(r[i] for i in range(field_count) if i not in sic)

        columns = lzip(*[extract(r) for r in header])
        names = ic + columns

        # If we find unnamed columns all in a single
        # level, then our header was too long.
        for n in range(len(columns[0])):
            if all(compat.to_str(c[n]) in self.unnamed_cols for c in columns):
                raise ParserError(
                    "Passed header=[{header}] are too many rows for this "
                    "multi_index of columns"
                    .format(header=','.join(str(x) for x in self.header))
                )

        # Clean the column names (if we have an index_col).
        if len(ic):
            col_names = [r[0] if (len(r[0]) and
                                  r[0] not in self.unnamed_cols) else None
                         for r in header]
        else:
            col_names = [None] * len(header)

        passed_names = True

        return names, index_names, col_names, passed_names
1038649
function compactGraphQLQuery (query) {
    let lexer = new Tokenizr()

    /*  configure lexical analysis  */
    lexer.rule(/#[^\r\n]*(?=\r?\n)/,                       (ctx, match) => { ctx.accept("comment") })
    lexer.rule(/"(?:\\"|[^"])*"/,                          (ctx, match) => { ctx.accept("string") })
    lexer.rule(/$[a-zA-Z_][a-zA-Z0-9_]*/,                  (ctx, match) => { ctx.accept("var") })
    lexer.rule(/[a-zA-Z_][a-zA-Z0-9_]*/,                   (ctx, match) => { ctx.accept("id") })
    lexer.rule(/[+-]?[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?/, (ctx, match) => { ctx.accept("number") })
    lexer.rule(/[ \t\r\n]+/,                               (ctx, match) => { ctx.accept("ws", " ") })
    lexer.rule(/[{}]/,                                     (ctx, match) => { ctx.accept("brace") })
    lexer.rule(/[[\]]/,                                    (ctx, match) => { ctx.accept("bracket") })
    lexer.rule(/[()]/,                                     (ctx, match) => { ctx.accept("parenthesis") })
    lexer.rule(/,/,                                        (ctx, match) => { ctx.accept("comma") })
    lexer.rule(/!/,                                        (ctx, match) => { ctx.accept("not") })
    lexer.rule(/\.\.\./,                                   (ctx, match) => { ctx.accept("ellipsis") })
    lexer.rule(/@/,                                        (ctx, match) => { ctx.accept("at") })
    lexer.rule(/:/,                                        (ctx, match) => { ctx.accept("colon") })
    lexer.rule(/./,                                        (ctx, match) => { ctx.accept("any") })
    lexer.input(query)
    lexer.debug(false)

    /*  fetch all parsed tokens  */
    let tokens = lexer.tokens()

    /*  remove whitespace tokens at harmless positions  */
    let output = ""
    let re = /^(?:brace|bracket|parenthesis|comma|colon)$/
    for (let i = 0; i < tokens.length; i++) {
        if (   tokens[i].type === "comment"
            || (   tokens[i].type === "ws"
                && (   (   i < tokens.length - 1
                        && tokens[i + 1].type.match(re))
                    || (    i > 0
                        && tokens[i - 1].type.match(re))))) {
            tokens.splice(i, 1)
            i--
        }
    }

    /*  assembly and return new query string  */
    tokens.forEach((token) => {
        output += token.value
    })
    return output
}
153056
function makeWordNet(input_path, preload){


	wn.isVerb = function( str, callback ){
		var word = wn.morphyPromise( str );
		var res = word.then(function(data){
			var posArray = data.pick( "part_of_speech" );
			return posArray.contains( "v" );
		});
		return res.nodeify( callback );
	};

	wn.isNoun = function(str, callback){
		var word = wn.morphyPromise(str);
		var res = word.then(function(data){
		  var posArray = data.pick("part_of_speech");
		  return posArray.contains("n");
		});
		return res.nodeify(callback);
	};

	wn.isAdjective = function(str, callback){
		var word = wn.morphyPromise(str);
		var res = word.then(function(data){
		  var posArray = data.pick("part_of_speech");
		  return posArray.contains("a") || posArray.contains("s");
		});
		return res.nodeify(callback);
	};

	wn.isAdverb = function(str, callback){
		var word = wn.morphyPromise(str);
		var res = word.then(function(data){
		  var posArray = data.pick("part_of_speech");
		  return posArray.contains("r");
		});
		return res.nodeify(callback);
	};

	wn.fetchSynset = function(identifier, callback){
		var ret;
	  var inputs = identifier.split(".");
	  if (!wn.preload){
		  var query = "SELECT s.synsetid AS synsetid, s.definition AS definition, s.pos AS pos, l.lexdomainname AS lexdomain FROM wordsXsensesXsynsets AS s LEFT JOIN lexdomains AS l ON l.lexdomainid = s.lexdomainid ";
		  query += "WHERE s.pos = $pos AND s.lemma = $lemma AND s.sensenum = $sensenum";

		  ret = db.eachAsync(query,{
			$lemma: inputs[0],
			$pos: inputs[1],
			$sensenum: inputs[2]
		   });
	  } else {
		  ret = wn.WORDSxSENSESxSYNSETSxLEXDOMAINS.then(function(d){
			  var search_lemma = inputs[0];
			  var res;
			  var candidateSet = d[search_lemma];
			  for (var i = 0; i < candidateSet.length; i++)
			  {
				  if (candidateSet[i].pos === inputs[1] && candidateSet[i].sensenum === inputs[2]){
					  res = candidateSet[i];
				  }
			  }
			  return res;
		  });
	  }

	   return ret.then(_appendLemmas).then(function(data){
		 return new wn.Synset(data);
	   }).nodeify(callback);
	};

	// Synset Class
	wn.Synset = function(obj){
		  this.synsetid = obj.synsetid;
		  this.words = obj.words;
		  this.definition = obj.definition;
		  this.pos = obj.pos;
		  this.lexdomain = obj.lexdomain;

		  if(obj.hypernym){
			this.hypernym = obj.hypernym;
		  }

		  if(obj.hyponym){
			  this.hyponym = obj.hyponym;
		  }

		  if(obj.holonymOf){
			  this.holonymOf = obj.holonymOf;
		  }

		  if(obj.domain_type){
			  this.domain_type = obj.domain_type;
		  }

		  if(obj.term_type){
			  this.term_type = obj.term_type;
		  }
	};

	wn.Synset.prototype = {
			  constructor: wn.Synset,
			  fetchSynset: function(callback){
				  var inputs = obj.split(".");

				  var query = "SELECT s.synsetid, s.definition, s.pos, l.lexdomainname AS lexdomain FROM wordsXsensesXsynsets AS s LEFT JOIN lexdomains AS l ON l.lexdomainid = s.lexdomainid";
				  query += "WHERE s.pos = $pos AND s.lemma = $lemma AND s.sensenum = $sensenum";

				  var ret = db.eachAsync(query,{
					   $lemma: inputs[0],
					   $pos: inputs[1],
					   $sensenum: inputs[2]
					 });

				  ret.then(function(data){
					  this.synsetid = data.synsetid;
					  this.definition = data.definition;
					  this.pos = data.pos;
					  this.lexdomain = data.lexdomain;

					  callback
				  });

				  fetched = true;
			  },
			  getExamples: function(callback){
				  var promise = _findSamplesArray(this.synsetid).map(function(item){
					return new wn.Example(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getLemmas: function(callback){
				var promise = _findLemmasArray(this.synsetid).map(function(item){
					return new wn.Word(item.lemma);
				});
				return promise.nodeify(callback);
			  },
			  getHypernyms: function(callback){
				  var promise = _findHypernymsArray(this.synsetid).map(_appendLemmas).map(function(item){
					   return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getHypernymsTree: function(callback){
				function getHypernymFromId(input){
					return _findHypernymsArray(input).map(_appendLemmas).map(function(item){
						item.hypernym = getHypernymFromId(item.synsetid);
						return Promise.props(item);
					}).map(function(item){
						var obj = new wn.Synset(item);
						return obj;
					});
				}
				var promise = getHypernymFromId(this.synsetid);
				return promise.nodeify(callback);
			  },
			  getHyponyms: function(callback){
				  var promise = _findHyponymsArray(this.synsetid).map(_appendLemmas).map(function(item){
					   return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getHyponymsTree: function(callback){
				  function getHyponymsFromId(input){
					  return _findHyponymsArray(input).map(_appendLemmas).map(function(item){
						  item.hyponym = getHyponymsFromId(item.synsetid);
						  return Promise.props(item);
					  }).map(function(item){
						 var obj = new wn.Synset(item);
						 return obj;
					  });
				  }
				  var promise = getHyponymsFromId(this.synsetid);
				  return promise.nodeify(callback);
			  },
			  getHolonyms: function(type, callback){
				  var promise = _findHolonymsArray(this.synsetid, type).map(_appendLemmas).map(function(item){
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getMeronyms: function(type, callback){
				  var promise = _findMeronymsArray(this.synsetid, type).map(_appendLemmas).map(function(item){
					 return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getSisterTerms: function(callback){
				  var promise = _findSisterTermsArray(this.synsetid).map(_appendLemmas).map(function(item){
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  causeOf: function(callback){
				  var promise = _findCauseOfArray(this.synsetid).map(_appendLemmas).map(function(item){
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getDomains: function(callback){

				  var classification;

				  function _findDomainsArray(synsetid){
					  var arr;
					  if (!wn.preload){
							var query = "SELECT synset2id, linkid FROM semlinks WHERE synset1id = $synset1id AND linkid IN (91, 93, 95)";
							arr = db.allAsync(query, {
								$synset1id: synsetid
							});
					  } else {
							arr = wn.SEMLINKS.then(function(data){
								return data.filter(function(e){
									return e.synset1id === synsetid && [91,93,95].contains(e.linkid);
								});
							});
					  }

						return arr.map(function(data){
							var obj = {};
							obj.synsetid = data.synset2id;

							switch(data.linkid){
							  case 91:
								classification = "topic";
							  break;
							  case 93:
								classification = "region";
							  break;
							  case 95:
								classification = "usage";
							  break;
							}

							return _findSynsetDefFromId(obj);
						});
					}

				  var promise = _findDomainsArray(this.synsetid).map(_appendLemmas).map(function(item){
					  item.domain_type = classification;
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getDomainTerms: function(callback){

				  var classification;

				  function _findDomainTermsArray(synsetid){
					  var arr;
					  if (!wn.preload){
							var query = "SELECT synset1id, linkid FROM semlinks WHERE synset2id = $synset2id AND linkid IN (92, 94, 96)";
							arr = db.allAsync(query, {
								$synset2id: synsetid
							});
						} else {
							arr = wn.SEMLINKS.then(function(data){
								return data.filter(function(e){
									return e.synset2id === synsetid && [92,94,96].contains(e.linkid);
								});
							});
						}

						return arr.map(function(data){
							var obj = {};
							obj.synsetid = data.synset1id;
							switch(data.linkid){
							  case 92:
								classification = "topic";
							  break;
							  case 94:
								classification = "region";
							  break;
							  case 96:
								classification = "usage";
							  break;
							}

						return _findSynsetDefFromId(obj);
		  });
					}

				  var promise = _findDomainTermsArray(this.synsetid).map(_appendLemmas).map(function(item){
					  item.term_type = classification;
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  toString: function(){
				  return this.definition;
			  },
			};

	// Example Class
	wn.Example = function(obj){
		this.synsetid = obj.synsetid;
		this.sampleid = obj.sampleid;
		this.sample = obj.sample;
	};

	wn.Example.prototype = {
			constructor: wn.Example,
			toString: function(){
				return this.sample;
			}
	};

	wn.print = function(obj){
		switch(obj.constructor){
		case Array:
			for (var i = 0; i < obj.length; i++){
				wn.print(obj[i]);
			}
		break;
		case wn.Synset:
			var synsetString = getSynsetString(obj, 0);
			console.log(synsetString);
		break;
		case wn.Word:
			console.log("L: " + obj.lemma);
		break;
		case wn.Example:
			console.log("E: " + obj.sample);
		break;
		}
	};

	function _findSisterTermsArray(synsetid){
		var hypernymIdArray = _findHypernymsArray(synsetid);
		return hypernymIdArray.map(function(data){
			var arr;
			if (!wn.preload){
				var query = "SELECT synset1id FROM semlinks WHERE synset2id = $synset2id AND linkid = 1";
				arr =  db.allAsync(query,{
					$synset2id: data.synsetid
				});
			} else {
				arr = wn.SEMLINKS.SISTERS.then(function(resultSet){
					return resultSet[data.synsetid] || [];
				});			}
			arr = arr.map(function(data){
				var obj = {};
				obj.synsetid = data.synset1id;
				return _findSynsetDefFromId(obj);
			}).map(_appendLemmas);
			var ret = data;
			ret.hyponym = arr;
			return Promise.props(ret);
		});
	}

	function _findHyponymsArray(synsetid){
		var arr;
		if (!wn.preload){
			var query = "SELECT synset2id FROM semlinks WHERE synset1id = $synset1id AND linkid = 2";
			 arr =  db.allAsync(query,{
				$synset1id: synsetid
			});
		} else {
			arr = wn.SEMLINKS.filter(function(e){
				return e.synset1id === synsetid && e.linkid === 1;
			});
		}

		return arr.map(function(data){
			var obj = {};
			obj.synsetid = data.synset2id;
			return _findSynsetDefFromId(obj);
		});
	}

	function _findCauseOfArray(synsetid){
		var arr;
		if (!wn.preload){
			var query = "SELECT synset2id FROM semlinks WHERE synset1id = $synset1id AND linkid = 23";
			arr = db.allAsync(query, {
			$synset1id: synsetid
		});
		} else {
			arr = wn.SEMLINKS.filter(function(e){
				return e.linkid === 23 && e.synset1id === synsetid;
			});
		}
		return arr.map(function(data){
			var obj = {};
			obj.synsetid = data.synset2id;
			return _findSynsetDefFromId(obj);
		});
	}

	function _appendLemmas(data){
		var promise = _findLemmasArray(data.synsetid).map(function(item){
			return new wn.Word(item.lemma);
		});
		var ret = data;
		ret.words = promise;
		return Promise.props(ret);
	}

	function _findHolonymsArray(synsetid, type){
		/*
		linkids are:
		part: 11
		member: 13
		substance: 15
		*/
		var ids;
		var linkid;
		var arr;

		if(type){
		  type = Array.isArray(type) ? type : new Array(type);
		  ids = type.map(function(elem){
			switch (elem) {
			case "part" : return 11;
			case "member" : return 13;
			case "substance" : return 15;
			}
		  });
		  linkid = "IN (" + ids.join(",") + ")";
		} else {
		  linkid = "IN (11,13,15)";
		}
		if (!wn.preload){
			var query = "SELECT synset1id FROM semlinks WHERE synset2id = $synset2id AND linkid " + linkid;
			arr = db.allAsync(query, {
				$synset2id: synsetid
			});
		}
		else {
			arr = wn.SEMLINKS.then(function(data){
				var ret = data.filter(function(e){
					if (type){
						return e.synset2id === synsetid && ids.contains(e.linkid);
					} else {
						return e.synset2id === synsetid;
					}
				});
				return ret;
			});
		}
		return arr.map(function(data){
			var obj = {};
			obj.synsetid = data.synset1id;
			return _findSynsetDefFromId(obj);
		});
	}

	function _findMeronymsArray(synsetid, type){
		/*
		linkids are:
		part: 12
		member: 14
		substance: 16
		*/
		var synID = synsetid;
		var linkid;
		if(type){
		  type = Array.isArray(type) ? type : new Array(type);
		  var ids = type.map(function(elem){
			  switch (elem) {
			  case "part" : return 12;
			  case "member" : return 14;
			  case "substance" : return 16;
			  }
		  });
		  linkid = "IN (" + ids.join(",") + ")";
		} else {
		  linkid = "IN (12,14,16)";
		}

		var arr;
		if(!wn.preload){
			var query = "SELECT synset1id FROM semlinks WHERE synset2id = $synset2id AND linkid " + linkid;
			arr = db.allAsync(query, {
				$synset2id: synID
			});
		} else {
			arr = wn.SEMLINKS.then(function(data){
				var ret = data.filter(function(e){
					return e.synset2id === synsetid && ids.contains(e.linkid);
				});
				return ret;
			});
		}
		return arr.map(function(data){
			var obj = {};
			obj.synsetid = data.synset1id;
			return _findSynsetDefFromId(obj);
		});
	}

	function _findHypernymsArray(synsetid){
		var arr;
		if (!wn.preload){
			var query = "SELECT synset2id FROM semlinks WHERE synset1id = $synset1id AND linkid = 1";
			arr =  db.allAsync(query,{
				$synset1id: synsetid
			});
		} else {
			arr = wn.SEMLINKS.HYPERNYMS.then(function(e){
				return e[synsetid] || [];
			});
		}
		var ret = arr.map(function(d){
			var obj = {};
			obj.synsetid = d.synset2id;
			return _findSynsetDefFromId(obj);
		});
		return ret;
	}

	function _findSamplesArray(synsetid){
		if(!wn.preload){
	  var query = "SELECT * FROM samples WHERE synsetid = $synsetid";
	  return db.allAsync(query,{
		  $synsetid: synsetid
	  });
		}
		else {
			var ret = wn.SAMPLES.then(function(d){
				return d[synsetid];
			});
			return ret;
		}
	}

	function _findLemmasArray(synsetid){
		var query = "SELECT words.lemma FROM words INNER JOIN senses ON words.wordid = senses.wordid WHERE senses.synsetid = $synsetid";
		return db.allAsync(query,{
			$synsetid: synsetid
		});
	}

	function _formSynsetsArray(data){
	  var SynsetArray = [];
	  for (var i = 0; i < data.length; i++){
		var obj =  _findSynsetDefFromId(data[i]);
		SynsetArray.push(obj);
	  }
	  return Promise.all(SynsetArray);
	}

	function _findSynsetDefFromId( data ) {
		var ret;
		if ( !wn.preload ) {
			var query = "SELECT ss.synsetid, ss.pos, ld.lexdomainname AS lexdomain, ss.definition";
			query += " FROM synsets AS ss INNER JOIN lexdomains AS ld ON ld.lexdomainid = ss.lexdomainid";
			query += " WHERE synsetid = $synsetid";
			ret = db.eachAsync( query, {
				$synsetid: data.synsetid
			});
		} else {
			ret = wn.SYNSETSxLEXDOMAINS.then( function( returnSet ) {
				return returnSet[data.synsetid];
			});
		}
		return ret;
	}

	return wn;
}