Commit fa81ceed authored by Lexie YU's avatar Lexie YU
Browse files

add function of counting runtime

parents 54a15a64 0fb9dd1b
......@@ -45,6 +45,8 @@ For sample testcases, please refer to [radicaltest.xml](https://cs-git-research.
* `-n` shows the line number along with each match
* Single and multi-file input
Filepath and line count option does not produce correct results when colourization is turned on. This is because an external issue with icgrep.
## **Iteration 1: Hard-Coding the Testcases into the Program**
In the first iteration, Radical Grep takes in pre-programmed inputs and returns the sentence(s) with the corresponding pattern.
......@@ -303,13 +305,13 @@ For inputs with more than one test files, filepaths are automatically shown. You
Input: -h -n 曰_ ../../QA/radicaltest/testfiles/*
Output: ../../QA/radicaltest/testfiles/test5:4:“金曰从革”,代表沉降、肃杀、收敛等性质,在人体为肺和大肠
../../QA/radicaltest/testfiles/test5:5:“水曰润下”,代表了滋润、下行、寒凉、闭藏的性质,在人体为肾和膀胱
../../QA/radicaltest/testfiles/test5:6:“木曰曲直”,代表生长、升发、条达、舒畅的功能,在人体为肝和膽
../../QA/radicaltest/testfiles/test5:7:“火曰炎上”,代表了温热、向上等性质,在人体为心和小肠
../../QA/radicaltest/testfiles/test5:8:“土曰稼穑”,代表了生化、承载、受纳等性质,在人体为脾和胃
../../QA/radicaltest/testfiles/test7:2:有人曰河海一体
../../QA/radicaltest/testfiles/test7:3:有人曰火水不容
../../QA/radicaltest/testfiles/test7:4:有人曰土水相得益彰
../../QA/radicaltest/testfiles/test5:5:“水曰润下”,代表了滋润、下行、寒凉、闭藏的性质,在人体为肾和膀胱
../../QA/radicaltest/testfiles/test5:6:“木曰曲直”,代表生长、升发、条达、舒畅的功能,在人体为肝和膽
../../QA/radicaltest/testfiles/test5:7:“火曰炎上”,代表了温热、向上等性质,在人体为心和小肠
../../QA/radicaltest/testfiles/test5:8:“土曰稼穑”,代表了生化、承载、受纳等性质,在人体为脾和胃
../../QA/radicaltest/testfiles/test7:2:有人曰河海一体
../../QA/radicaltest/testfiles/test7:3:有人曰火水不容
../../QA/radicaltest/testfiles/test7:4:有人曰土水相得益彰
## **References**
......
......@@ -3,7 +3,6 @@
#include <string>
#include <iostream>
#include <sstream>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/ErrorHandling.h>
using namespace std;
......@@ -12,63 +11,34 @@ using namespace UCD::KRS_ns;
namespace BS
{
const UCD::UnicodeSet&& UnicodeSetTable::get_uset(string radical, bool indexMode, bool mixedMode) //Map the input radical to the corresponding UnicodeSet predefined in kRSKangXi.h
{
if (indexMode)
{ //search using the index (e.g. 85_)
/*try
{
int num = std::stoi(radical); //checks if the input is anything other than a number
if (num < 1 || num > 214)
{ //if input is a number not in range [1,214]; terminate program
llvm::report_fatal_error("A radical set for this input does not exist.\n Enter a integer in [1,214], followed by _.");
}
}
catch (std::invalid_argument)
{ //if input not an integer, terminate program
llvm::report_fatal_error("A radical set for this input does not exist.\n Enter a integer in [1,214], followed by _.");
}*/
if(_unicodeset_radical_table.find(radical) != _unicodeset_radical_table.end())
return std::move(*_unicodeset_radical_table[radical]);
else
llvm::report_fatal_error("A radical set for this input does not exist.\n Enter a integer in [1,214], followed by _.");
//return std::move(UCD::UnicodeSet());
}
else if (mixedMode)
{
if(mixed_table.find(radical)!=mixed_table.end())
return std::move(*mixed_table[radical]);
else
//return std::move(UCD::UnicodeSet());
llvm::report_fatal_error("A radical set for this input does not exist.");
}
else
{ //search using the actual radical (e.g. 氵_)
if(radical_table.find(radical) != radical_table.end()) {
return std::move(*radical_table[radical]);
} else {
llvm::report_fatal_error("A radical set for this input does not exist.");
//return std::move(UCD::UnicodeSet());
}
static UnicodeSetTable ucd_radical;
const UCD::UnicodeSet&& UnicodeSetTable::get_uset(string radical, bool indexMode, bool mixedMode) //Map the input radical to the corresponding UnicodeSet predefined in kRSKangXi.h
{
if (indexMode) { //search using the index (e.g. 85_)
if(_unicodeset_radical_table.find(radical) != _unicodeset_radical_table.end())
return std::move(*_unicodeset_radical_table[radical]);
else
llvm::report_fatal_error("A radical set for this input does not exist.\n Enter a integer in [1,214], followed by _.");
} else if (mixedMode) {
if(mixed_table.find(radical)!=mixed_table.end())
return std::move(*mixed_table[radical]);
else
llvm::report_fatal_error("A radical set for this input does not exist.");
} else { //search using the actual radical (e.g. 氵_)
if(radical_table.find(radical) != radical_table.end())
return std::move(*radical_table[radical]);
else
llvm::report_fatal_error("A radical set for this input does not exist.");
}
}
}
}
//Search for the results by making CCs of each radical and pushing them the vector REs
std::vector<re::RE*> RadicalValuesEnumerator::createREs(bool indexMode, bool mixMode, bool altMode)
{
std::vector<re::RE*> REs;
std::vector<re::RE*> temp;
std::vector<re::RE*> temp0;
//SAMPLE CASES FOR altMode:
//(WORKING):
//./radicalgrep -alt -c auto {火/水/土}_曰_ ../QA/radicaltest/testfiles/*
//./radicalgrep -alt -c auto {火/水}_曰_ ../../QA/radicaltest/testfiles/*
//./radicalgrep -alt -c auto 曰_{火/水/土}_水_ ../QA/radicaltest/testfiles/*
//./radicalgrep -alt -c auto 水_{火/水}_ ../../QA/radicaltest/testfiles/*
// ./radicalgrep -alt -c auto -m 水_{86/85}_ ../../QA/radicaltest/testfiles/*
// ./radicalgrep -alt -c auto 亻_衣_{生/亅} ../../QA/radicaltest/testfiles/*
/*Suppose we have radical expression 亻_衣_{生/亅} as an example.
亻and 衣 are stored in the zi vector, and 生 and 亅 are in the reTemp vector*/
......@@ -96,7 +66,7 @@ namespace BS
}
}
else if(0<position<c1-1)
else if (position > 0 && position < c1-1)
{
for (std::size_t i = 0; i < zi.size(); i++)
{
......
......@@ -17,14 +17,13 @@
#include <re/parse/parser.h>
#include <re/toolchain/toolchain.h>
#include <unicode/data/kRSKangXi.h>
#include <llvm/Support/ErrorHandling.h>
enum ColoringType {alwaysColor, autoColor, neverColor};
extern ColoringType ColorFlag;
extern bool LineNumberFlag;
extern bool WithFilenameFlag;
const int MatchFoundExitCode=0;
const int MatchNotFoundExitCode=1;
const int MatchFoundExitCode = 0;
const int MatchNotFoundExitCode = 1;
namespace BS
{
......@@ -44,7 +43,7 @@ namespace BS
static map<string, const UCD::UnicodeSet*> mixed_table;
};
static UnicodeSetTable ucd_radical;
//static UnicodeSetTable ucd_radical;
class RadicalValuesEnumerator
{
......
......@@ -46,9 +46,6 @@
namespace fs = boost::filesystem;
//const int MatchFoundExitCode=0;
//const int MatchNotFoundExitCode=1;
using namespace std;
using namespace llvm;
using namespace pablo;
......@@ -64,15 +61,13 @@ static cl::opt<bool> mixMode("m", cl::desc("Use both radical character and radic
static cl::opt<bool> altMode("alt", cl::desc("Use regular expressions to search for multiple phrases."), cl::init(false), cl::cat(radicalgrepFlags));
//Adpated from grep_interface.cpp
ColoringType ColorFlag;
//options for colourization; (e.g. -c auto)
static cl::opt<ColoringType, true> Color("c", cl::desc("Set the colorization of the output."),
cl::values(clEnumValN(alwaysColor, "always", "Turn on colorization when outputting to a file and terminal"),
clEnumValN(autoColor, "auto", "Turn on colorization only when outputting to terminal"),
clEnumValN(neverColor, "never", "Turn off output colorization")
CL_ENUM_VAL_SENTINEL), cl::cat(radicalgrepFlags), cl::location(ColorFlag), cl::init(neverColor));
bool LineNumberFlag;
bool LineNumberFlag, WithFilenameFlag;
static cl::opt<bool, true> LineNumberOption("n", cl::location(LineNumberFlag), cl::desc("Show the line number with each matching line."), cl::cat(radicalgrepFlags));
bool WithFilenameFlag;
static cl::opt<bool, true> WithFilenameOption("h", cl::location(WithFilenameFlag), cl::desc("Show the file name with each matching line."), cl::cat(radicalgrepFlags));
bool CLKCountingFlag;
static cl::opt<bool, true> CLKCountingOption("clk", cl::location(CLKCountingFlag), cl::desc("Show the runtime of the function."), cl::cat(radicalgrepFlags));
......@@ -88,6 +83,7 @@ int main(int argc, char* argv[])
{
argv::DirectoriesFlag=argv::Recurse;
}
CPUDriver pxDriver("radicalgrep");
allfiles=argv::getFullFileList(pxDriver, inputfiles);
......@@ -103,18 +99,19 @@ int main(int argc, char* argv[])
if (WithFilenameFlag) grep->showFileNames();
if (LineNumberFlag) grep->showLineNumbers();
//turn on colorizartion if specified by user
if ((ColorFlag == alwaysColor) || ((ColorFlag == autoColor) && isatty(STDOUT_FILENO))) {
grep->setColoring();
}
if ((ColorFlag == alwaysColor) || ((ColorFlag == autoColor) && isatty(STDOUT_FILENO))) grep->setColoring();
grep->initFileResult(allfiles); //Defined in file grep_engine, Initialize results of each file
grep->initREs(radicalREs); //Defined in file grep_engine, Initialize the output
grep->grepCodeGen(); //Return the number of the result
const bool matchFound=grep->searchAllFiles(); //Return if there have found any result, if yes, return true, else return false
if(matchFound==false) //if there does not exist any results
cout<<"Can not find the results!"<<endl;
//if there does not exist any results
if(matchFound==false) cout<<"Can not find the results!"<<endl;
if(CLKCountingFlag==true)
{
long endtime=clock();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment