LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
toolnumber.h
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifndef LIMA_WORDSENSEDISAMBIGUATION_TOOLNUMBER_H
7#define LIMA_WORDSENSEDISAMBIGUATION_TOOLNUMBER_H
8
9namespace Lima
10{
11namespace LinguisticProcessing
12{
13namespace WordSenseDisambiguation
14{
15
16
23{
24public:
26
28
29
30 static std::vector<int> & makePermutation(int size)
31 {
32 std::vector<int> * permut = new std::vector<int>(size);
33 std::vector<int> avail(size);
34 // Generate a list {0,1,2,3,...,size-1}
35 for (int i = 0; i < size; i++)
36 avail[i] = i;
37 int index;
38 for (int i = 0; i < size; i++)
39 {
40 // Pick a random element from the list
41 index = rand() % (size-i);
42 (*permut)[i] = avail[index];
43 // And replace it with the last element in the list (so that it is no longer available)
44 avail[index] = avail.back();
45 // Remove the last element
46 avail.pop_back();
47 }
48 return *permut;
49 }
50
51
52
53 static float magiccosine ( char *a, float *b, int dim , int nPairs)
54 {
55 double sum = 0.;
56 for (int p = 0; p < nPairs ; p++) {
57 uint64_t pos;
58 memcpy (&pos, a + p*(sizeof(uint)+sizeof(float)), sizeof(uint));
59 if (pos < (uint) dim) {
60 float value;
61 memcpy (&value, a + p*(sizeof(uint)+sizeof(float))+ sizeof(uint), sizeof(float));
62 /*cerr << "Value : " << (double)value << endl;
63 cerr << "b[pos] : " << (double)b[pos]<< endl;*/
64 sum+= (double)value * (double)b[pos];
65 }
66 }
67 return (float)sum;
68 }
69
70
71
72};
73
74
75
76}
77}
78}
79
80
81#endif // LIMA_WORDSENSEDISAMBIGUATION_TOOLNUMBER_H
static std::vector< int > & makePermutation(int size)
Definition toolnumber.h:30
static float magiccosine(char *a, float *b, int dim, int nPairs)
Definition toolnumber.h:53
NAUTITIA.