-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcompStrMetricMain.cc
More file actions
113 lines (106 loc) · 4.98 KB
/
compStrMetricMain.cc
File metadata and controls
113 lines (106 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
Copyright 2014 Neustar Inc.
Licensed 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <map>
#include <list>
#include "compStrMetric.h"
// Length of the inpute line (the two strings to be compared)
#define INPUTLINELEN 200
//
using namespace std;
//
// The main function starts the string similarity program.
// It takes two files as inputs.
// The first file consists of the pairs of strings whose
// string similarity values are to be obtained by the computeMetrics
// string similarity program.
// The output file is filled with program output after the program finishes running.
// The output file consists of the pairs of strings to be compared and
// their corresponding string similarity score values
//
// This main function calls the computeStrMetric function by passing
// a pair of strings.
// The computeStrMetric function returns the strMetricStructReturnLocal
// structure which consists of the string similarity scores of the two strings.
//
// The main function then puts the output into the output file and also
// displays it on the standard output (screen).
int main(int argc, char** argv) {
// Program usage
if (argc < 1) {
printf("Program usage: ./computeMetrics inputFilePath/inputFile outputFilePath/outputFile \n");
return -1;
}
if (strcmp(argv[1], argv[2]) == 0) {
printf("Input and output file names should not be the same.\n");
return -1;
}
// String input file
FILE* stringsFile = fopen(argv[1], "r");
//
// Output file
FILE* outputFile = fopen(argv[2], "w");
//
// Return structure of the string metric computation functions
strMetricStruct strMetricStructReturnLocal;
//
// Two strings passed to the string metric function
char* compDistArg[2];
//
// The whole input line. A full name is not longer than 100 characters (assumption)
char inputeLine[INPUTLINELEN];
//
// For the input tokenizer
int lindex = 0;
//
printf("string1 string2 compDistPerc wcompDistPerc sseqWsPerc sstrWsPerc sqrtsseqWsPerc wsumsseqWsPerc matchRatio \n");
printf("-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
//
// And in output file
fprintf(outputFile, "string1 string2 compDistPerc wcompDistPerc sseqWsPerc sstrWsPerc sqrtsseqWsPerc wsumsseqWsPerc matchRatio \n");
fprintf(outputFile, "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
//
// Read the two strings from every inpute line
// Get the string metric values and
// Write results to standard output and to output file
//
while (fgets(inputeLine, INPUTLINELEN, stringsFile) != NULL) {
if (inputeLine[strlen(inputeLine)-1] == '\n') {
inputeLine[strlen(inputeLine)-1] = '\0';
}
//
lindex = 0;
compDistArg[lindex] = strtok(inputeLine, "|");
while (compDistArg[lindex] != NULL) {
lindex++;
compDistArg[lindex] = strtok(NULL, "|");
}
//
strMetricStructReturnLocal = computeStrMetric(compDistArg);
//
// Write results to standard output (screen)
printf("%-40s %-40s %-12f %-12f %-12f %-12f %-12f %-12f %-12f \n", compDistArg[0], compDistArg[1], strMetricStructReturnLocal.compDistPercent, strMetricStructReturnLocal.wcompDistPercent, strMetricStructReturnLocal.sseqWsPercent, strMetricStructReturnLocal.sstrWsPercent, strMetricStructReturnLocal.sqrtsseqWsPercent, strMetricStructReturnLocal.wsumsseqWsPercent, strMetricStructReturnLocal.matchRatio);
//
// Write results to output file
fprintf(outputFile, "%-40s %-40s %-12f %-12f %-12f %-12f %-12f %-12f %-12f \n", compDistArg[0], compDistArg[1], strMetricStructReturnLocal.compDistPercent, strMetricStructReturnLocal.wcompDistPercent, strMetricStructReturnLocal.sseqWsPercent, strMetricStructReturnLocal.sstrWsPercent, strMetricStructReturnLocal.sqrtsseqWsPercent, strMetricStructReturnLocal.wsumsseqWsPercent, strMetricStructReturnLocal.matchRatio);
}
//
// CLose input and output files
fclose(stringsFile);
fclose(outputFile);
//
return 0;
}