//public static void Test_FindInFile_01(string file) //{ // //RegexValuesList regexList = new RegexValuesList(XmlConfig.CurrentConfig.GetElements("QuestionInfos/QuestionInfo"), compileRegex: true); // RegexValuesList regexList = QuestionRun.GetQuestionRegexValuesList(); // foreach (string line in zFile.ReadLines(file)) // { // string line2 = line.Trim(); // if (line2 == "") // continue; // Trace.WriteLine($"read : \"{line2}\""); // FindText findText = regexList.Find(line2); // if (findText.Found) // { // foreach (KeyValuePair<string, ZValue> namedValue in findText.matchValues.GetValues()) // Trace.WriteLine($" found : {namedValue.Key} = \"{namedValue.Value}\""); // } // else // { // Trace.WriteLine($" unknow text"); // } // } //} public static void Test_Find_02(string text, RegexValuesList regexList) { Trace.WriteLine($"text : \"{text}\""); FindText_v2 findText = regexList.Find(text); if (findText.Success) { //MatchValues matchValues = findText.matchValues; while (findText.Success) { Trace.WriteLine(); Trace.WriteLine($" found : index {findText.Match.Index} length {findText.Match.Length}"); foreach (KeyValuePair <string, ZValue> namedValue in findText.GetValues()) { Trace.WriteLine($" : {namedValue.Key} = \"{namedValue.Value}\""); } //matchValues = matchValues.Next(); findText.Next(); } } else { Trace.WriteLine($" unknow text"); } }
public static void Init() { InitImage(XmlConfig.CurrentConfig.GetElement("Image")); _textInfoRegexList = new RegexValuesList(XmlConfig.CurrentConfig.GetElements("RapideDdl/Parameters/TextInfos/TextInfo")); _printTextValuesManager = new PrintTextValuesManager(new RegexValuesList(XmlConfig.CurrentConfig.GetElements("TextInfos/TextInfo")), _trimFunc1); //InitImagesToSkip(); }
public static void Test_FindDate_01(RegexValuesList dateRegexList, string file) { file = zPath.Combine(GetDirectoryDate(), file); string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_out"); Trace.WriteLine("Test_FindDate \"{0}\" (nb date regex {1})", file, dateRegexList.Count); //Trace.CurrentTrace.DisableBaseLog(); Trace.CurrentTrace.DisableViewer = true; //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile); Trace.CurrentTrace.AddOnWrite("Test_FindDate_01", WriteToFile.Create(traceFile, FileOption.RazFile).Write); try { TraceRegexValuesList(dateRegexList); Trace.WriteLine(); foreach (BsonDocument document in zMongo.BsonRead <BsonDocument>(file)) { FindDate(dateRegexList, document["text"].AsString); } } finally { //Trace.CurrentTrace.EnableBaseLog(); //Trace.CurrentTrace.RemoveTraceFile(traceFile); Trace.CurrentTrace.RemoveOnWrite("Test_FindDate_01"); Trace.CurrentTrace.DisableViewer = false; } }
public static RegexValuesList CreateQuestionRegexValuesList() { RegexValuesList regexValuesList = new RegexValuesList(XmlConfig.CurrentConfig.GetElements("QuestionInfos_v2/QuestionInfo"), compileRegex: true); //regexValuesList.Add(XmlConfig.CurrentConfig.GetElements("ResponseInfos/ResponseInfo"), compileRegex: true); return(regexValuesList); }
public static void Test_RegexValues(IEnumerable <XElement> elements, string input) { Trace.WriteLine("\"{0}\" : ", input); RegexValuesList rvs = new RegexValuesList(elements); //FindText_old findText = rvs.Find_old(input); FindText findText = rvs.Find(input); if (findText.Found) { //NamedValues<ZValue> values = findText.regexValues.GetValues_old(); NamedValues <ZValue> values = findText.matchValues.GetValues(); //Trace.WriteLine(" found \"{0}\" {1} values", findText.regexValues.Name, values.Count); Trace.WriteLine(" found \"{0}\" {1} values", findText.matchValues.Name, values.Count); foreach (KeyValuePair <string, ZValue> value in values) { if (value.Value is ZStringArray) { Trace.WriteLine(" value {0} = [{1}] {2}", value.Key, ((string[])value.Value).Length, ((string[])value.Value).zToStringValues(s => "\"" + s.zToStringOrNull() + "\"")); } else { Trace.WriteLine(" value {0} = \"{1}\"", value.Key, value.Value.zToStringOrNull()); } } } else { Trace.WriteLine(" not found"); } Trace.WriteLine(); }
public static void Test2(RegexValuesList regexValuesList, string text, bool contiguous = false) { Trace.WriteLine("Input : {0}", text); //FindText findText = regexValuesList.Find(text); FindText_v2 findText = regexValuesList.Find(text); if (!findText.Success) { Trace.WriteLine("Result : not found"); return; } while (findText.Success) { Trace.Write($"found \"{findText.Text}\" position {findText.Match.Index + 1} length {findText.Match.Length}"); NamedValues <ZValue> values = findText.GetValues(); if (values.Count > 0) { Trace.Write(" values"); foreach (KeyValuePair <string, ZValue> value in findText.GetValues()) { Trace.Write($" \"{value.Key}\" = \"{value.Value}\""); } } if (findText.Attributes.Count > 0) { Trace.Write(" attributes"); foreach (KeyValuePair <string, string> attribute in findText.Attributes) { Trace.Write($" \"{attribute.Key}\" = \"{attribute.Value}\""); } } Trace.WriteLine(); findText.FindNext(contiguous); } }
public static void Test(RegexValuesList regexValuesList, string text) { Trace.WriteLine("Input : {0}", text); FindText findText = regexValuesList.Find(text); if (!findText.Found) Trace.WriteLine("Result : not found"); else { Trace.WriteLine("Result : found"); Trace.WriteLine(" Text : \"{0}\"", findText.Text); Trace.WriteLine(" Key : \"{0}\"", findText.matchValues.Key); Trace.WriteLine(" Name : \"{0}\"", findText.matchValues.Name); Trace.WriteLine(" Pattern : \"{0}\"", findText.matchValues.Pattern); Trace.WriteLine(" Attributes : {0}", findText.matchValues.Attributes.Count); foreach (KeyValuePair<string, string> attribute in findText.matchValues.Attributes) Trace.WriteLine(" Attribute : \"{0}\" = \"{1}\"", attribute.Key, attribute.Value); NamedValues<ZValue> values = findText.matchValues.GetValues(); Trace.WriteLine(" GetValues() : {0}", findText.matchValues.Attributes.Count); foreach (KeyValuePair<string, ZValue> value in values) Trace.WriteLine(" Value : \"{0}\" = \"{1}\"", value.Key, value.Value); values = findText.matchValues.GetAllValues(); Trace.WriteLine(" GetAllValues() : {0}", findText.matchValues.Attributes.Count); foreach (KeyValuePair<string, ZValue> value in values) Trace.WriteLine(" AllValue : \"{0}\" = {1}", value.Key, value.Value); } }
public static void FindDate(RegexValuesList dateRegexList, string title) { bool found = false; foreach (RegexValues rv in dateRegexList.Values) { //rv.Match_old(title); MatchValues matchValues = rv.Match(title); //if (rv.Success_old) if (matchValues.Success) { //NamedValues<ZValue> values = rv.GetValues_old(); NamedValues <ZValue> values = matchValues.GetValues(); Date date; DateType dateType; //Trace.Write(" date "); //found = zdate.TryCreateDate(values, out date); //if (found) // Trace.Write("{0:dd-MM-yyyy}", date); //else // Trace.Write("not found "); //Trace.Write(" "); //values.zTrace(); //Trace.WriteLine(" found date : {0}", rv.MatchValue_old); Trace.WriteLine(" found date : {0}", matchValues.Match.Value); //Trace.WriteLine(" remain text : {0}", rv.MatchReplace_old("_")); Trace.WriteLine(" remain text : {0}", matchValues.Replace("_")); Trace.Write(" date : "); found = zdate.TryCreateDate(values, out date, out dateType); if (found) { Trace.Write("{0:dd-MM-yyyy} type {1}", date, dateType); } else { Trace.Write("not found "); } Trace.WriteLine(); Trace.Write(" values : "); values.zTrace(); Trace.WriteLine(); if (found) { break; } } } if (!found) { Trace.WriteLine(" date not found "); } }
public static RegexValuesList CreateAnkiRegexValuesList() { string configFile = @"c:\pib\drive\google\dev\.net\Apps\tools\anki\anki.config.xml"; XmlConfig config = new XmlConfig(configFile); RegexValuesList regexValuesList = new RegexValuesList(config.GetElements("QuestionInfos/QuestionInfo"), compileRegex: true); //regexValuesList.Add(config.GetElements("ResponseInfos/ResponseInfo"), compileRegex: true); return(regexValuesList); }
private static void TraceRegexValuesList(RegexValuesList regexList) { int i = 1; foreach (RegexValues regex in regexList.Values) { Trace.WriteLine("pattern {0} \"{1}\"", i++, regex.Pattern); } }
public static NamedValues <ZValue> Test_Find_01(string text, RegexValuesList regexList) { Trace.WriteLine($"text : \"{text}\""); //RegexValuesList regexList = new RegexValuesList(XmlConfig.CurrentConfig.GetElements("QuestionInfos/QuestionInfo"), compileRegex: true); //FindText findText = QuestionRun.GetQuestionRegexValuesList().Find(text); FindText_v2 findText = regexList.Find(text); Trace.WriteLine($"found : {findText.Success}"); return(findText.GetAllValues()); }
public static PrintFileManager_v2 CreatePrintFileManager_v2(UncompressQueueManager uncompressManager = null, bool simulate = false, bool moveFiles = false, bool moveInfoFiles = false) { DownloadAutomateManagerCreator downloadAutomateManagerCreator = GetDownloadAutomateManagerCreator(); if (uncompressManager == null) uncompressManager = downloadAutomateManagerCreator.CreateUncompressManager(); RegexValuesList bonusDirectories = new RegexValuesList(XmlConfig.CurrentConfig.GetConfig("PrintList2Config").GetElements("BonusDirectories/Directory"), compileRegex: true); PrintFileManager_v2 printFileManager = new PrintFileManager_v2(); printFileManager.Simulate = simulate; printFileManager.MoveFiles = moveFiles; printFileManager.MoveInfoFiles = moveInfoFiles; printFileManager.UncompressManager = uncompressManager; printFileManager.BonusDirectories = bonusDirectories; return printFileManager; }
//public static void Test_SelectPostManager_01(string query, int limit = 0) //{ // SelectPostManager selectPostManager = new SelectPostManager(XmlConfig.CurrentConfig.GetElement("SelectPosts")); // MongoCursor<BsonDocument> cursor = pb.Data.Mongo.MongoCommand.Find("dl", "RapideDdl_Detail2", query, fields: "{ 'download.title': 1 }", limit: limit, sort: "{ 'download.creationDate': -1 }"); // foreach (BsonDocument document in cursor) // { // string title = document["download"]["title"].AsString; // //Trace.Write("FindDate : {0,-100}", "\"" + title + "\""); // Trace.WriteLine("FindDate : \"{0}\"", title); // selectPostManager.FindDate(title); // } //} public static void Test_FindDate_01(string query, int limit = 0) { //SelectPostManager selectPostManager = new SelectPostManager(XmlConfig.CurrentConfig.GetElement("SelectPosts")); // zElements("Dates/Date") RegexValuesList dateRegexList = new RegexValuesList(XmlConfig.CurrentConfig.GetElement("SelectPosts").zXPathElements("Dates/Date"), compileRegex: true); MongoCursor<BsonDocument> cursor = pb.Data.Mongo.MongoCommand.Find("dl", "RapideDdl_Detail2", query, fields: "{ 'download.title': 1 }", limit: limit, sort: "{ 'download.creationDate': -1 }"); foreach (BsonDocument document in cursor) { string title = document["download"]["title"].AsString; //Trace.Write("FindDate : {0,-100}", "\"" + title + "\""); Trace.WriteLine("FindDate : \"{0}\"", title); FindDate(dateRegexList, title); Trace.WriteLine(); } }
public static void FindDate(RegexValuesList dateRegexList, string title) { bool found = false; foreach (RegexValues rv in dateRegexList.Values) { //rv.Match_old(title); MatchValues matchValues = rv.Match(title); //if (rv.Success_old) if (matchValues.Success) { //NamedValues<ZValue> values = rv.GetValues_old(); NamedValues<ZValue> values = matchValues.GetValues(); Date date; DateType dateType; //Trace.Write(" date "); //found = zdate.TryCreateDate(values, out date); //if (found) // Trace.Write("{0:dd-MM-yyyy}", date); //else // Trace.Write("not found "); //Trace.Write(" "); //values.zTrace(); //Trace.WriteLine(" found date : {0}", rv.MatchValue_old); Trace.WriteLine(" found date : {0}", matchValues.Match.Value); //Trace.WriteLine(" remain text : {0}", rv.MatchReplace_old("_")); Trace.WriteLine(" remain text : {0}", matchValues.Replace("_")); Trace.Write(" date : "); found = zdate.TryCreateDate(values, out date, out dateType); if (found) Trace.Write("{0:dd-MM-yyyy} type {1}", date, dateType); else Trace.Write("not found "); Trace.WriteLine(); Trace.Write(" values : "); values.zTrace(); Trace.WriteLine(); if (found) break; } } if (!found) Trace.WriteLine(" date not found "); }
//public static void Test_SelectPostManager_01(string query, int limit = 0) //{ // SelectPostManager selectPostManager = new SelectPostManager(XmlConfig.CurrentConfig.GetElement("SelectPosts")); // MongoCursor<BsonDocument> cursor = pb.Data.Mongo.MongoCommand.Find("dl", "RapideDdl_Detail2", query, fields: "{ 'download.title': 1 }", limit: limit, sort: "{ 'download.creationDate': -1 }"); // foreach (BsonDocument document in cursor) // { // string title = document["download"]["title"].AsString; // //Trace.Write("FindDate : {0,-100}", "\"" + title + "\""); // Trace.WriteLine("FindDate : \"{0}\"", title); // selectPostManager.FindDate(title); // } //} public static void Test_FindDate_01(string query, int limit = 0) { //SelectPostManager selectPostManager = new SelectPostManager(XmlConfig.CurrentConfig.GetElement("SelectPosts")); // zElements("Dates/Date") RegexValuesList dateRegexList = new RegexValuesList(XmlConfig.CurrentConfig.GetElement("SelectPosts").zXPathElements("Dates/Date"), compileRegex: true); MongoCursor <BsonDocument> cursor = pb.Data.Mongo.MongoCommand.Find("dl", "RapideDdl_Detail2", query, fields: "{ 'download.title': 1 }", limit: limit, sort: "{ 'download.creationDate': -1 }"); foreach (BsonDocument document in cursor) { string title = document["download"]["title"].AsString; //Trace.Write("FindDate : {0,-100}", "\"" + title + "\""); Trace.WriteLine("FindDate : \"{0}\"", title); FindDate(dateRegexList, title); Trace.WriteLine(); } }
public static PrintFileManager_v2 CreatePrintFileManager_v2(UncompressQueueManager uncompressManager = null, bool simulate = false, bool moveFiles = false, bool moveInfoFiles = false) { DownloadAutomateManagerCreator downloadAutomateManagerCreator = GetDownloadAutomateManagerCreator(); if (uncompressManager == null) { uncompressManager = downloadAutomateManagerCreator.CreateUncompressManager(); } RegexValuesList bonusDirectories = new RegexValuesList(XmlConfig.CurrentConfig.GetConfig("PrintList2Config").GetElements("BonusDirectories/Directory"), compileRegex: true); PrintFileManager_v2 printFileManager = new PrintFileManager_v2(); printFileManager.Simulate = simulate; printFileManager.MoveFiles = moveFiles; printFileManager.MoveInfoFiles = moveInfoFiles; printFileManager.UncompressManager = uncompressManager; printFileManager.BonusDirectories = bonusDirectories; return(printFileManager); }
public static void Test_FindInFile_01(string file, RegexValuesList regexList) { //RegexValuesList regexList = QuestionRun.GetResponseRegexValuesList(); int lineNumber = 0; foreach (string line in zFile.ReadLines(file)) { //string line2 = line.Trim(); //if (line2 == "") // continue; lineNumber++; if (line == "") { continue; } Trace.WriteLine(); Trace.WriteLine($"read : line {lineNumber} \"{line}\""); FindText_v2 findText = regexList.Find(line); if (findText.Success) { //MatchValues matchValues = findText.matchValues; while (findText.Success) { Trace.WriteLine(); Trace.WriteLine($" found : index {findText.Match.Index} length {findText.Match.Length}"); foreach (KeyValuePair <string, ZValue> namedValue in findText.GetValues()) { Trace.WriteLine($" : {namedValue.Key} = \"{namedValue.Value}\""); } //matchValues = matchValues.Next(); findText.Next(); } } else { Trace.WriteLine($" unknow text"); } } }
public static void Test(RegexValuesList regexValuesList, string text) { Trace.WriteLine("Input : {0}", text); //FindText findText = regexValuesList.Find(text); FindText_v2 findText = regexValuesList.Find(text); if (!findText.Success) { Trace.WriteLine("Result : not found"); } else { Trace.WriteLine("Result : found"); Trace.WriteLine(" Text : \"{0}\"", findText.Text); Trace.WriteLine(" Key : \"{0}\"", findText.Key); Trace.WriteLine(" Name : \"{0}\"", findText.Name); Trace.WriteLine(" Pattern : \"{0}\"", findText.Pattern); Trace.WriteLine(" Attributes : {0}", findText.Attributes.Count); foreach (KeyValuePair <string, string> attribute in findText.Attributes) { Trace.WriteLine(" Attribute : \"{0}\" = \"{1}\"", attribute.Key, attribute.Value); } NamedValues <ZValue> values = findText.GetValues(); Trace.WriteLine(" GetValues() : {0}", values.Count); foreach (KeyValuePair <string, ZValue> value in values) { Trace.WriteLine(" Value : \"{0}\" = \"{1}\"", value.Key, value.Value); } values = findText.GetAllValues(); Trace.WriteLine(" GetAllValues() : {0}", values.Count); foreach (KeyValuePair <string, ZValue> value in values) { Trace.WriteLine(" AllValue : \"{0}\" = {1}", value.Key, value.Value); } } }
public static void Init(XElement xe) { _xmlDirectory = xe.zXPathValue("CacheDirectory"); _xmlImageDirectory = xe.zXPathValue("ImageCacheDirectory", _xmlImageDirectory); _textInfoRegexList = new RegexValuesList(xe.XPathSelectElements("TextInfo")); }
//private bool _extractValuesFromText = true; public PrintTextValuesManager(RegexValuesList textInfoRegexList, Func<string, string> trim = null) { _textInfoRegexList = textInfoRegexList; _trim = trim; }
private void init(XElement xelement) { _directory = xelement.zXPathValue("Directory"); Dictionary <string, RegexValuesModel> regexModels = new Dictionary <string, RegexValuesModel>(); // zElements("FilenamesModel/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenamesModel/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); regexModels.Add(rvm.key, rvm); } _regexModels = new Dictionary <string, RegexValuesModel>(); // zElements("FilenameModels/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenameModels/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); _regexModels.Add(rvm.key, rvm); } // zElements("FilenameDates/FilenameDate") _dateRegexList = new RegexValuesList(xelement.zXPathElements("FilenameDates/FilenameDate")); //if (_trace) // Trace.CurrentTrace.WriteLine("_dateRegexList {0}", _dateRegexList.Count); _printRegexList = new RegexValuesList(); _printRegexList2 = new RegexValuesList(); _prints = new Dictionary <string, Print1>(); // zElements("Prints/Print") foreach (XElement xe in xelement.zXPathElements("Prints/Print")) { Print1 print = null; switch (xe.zXPathValue("Class")) { case "LeMonde": print = new LeMonde(xe, _directory, _regexModels); break; case "LeParisien": print = new LeParisien(xe, _directory, _regexModels); break; case "LeVifExpress": print = new LeVifExpress(xe, _directory, _regexModels); break; default: print = new Print1(xe, _directory, _regexModels); break; } string name = print.Name; _prints.Add(name, print); int n = 1; // zElements("Filenames/Filename") foreach (XElement xe2 in xe.zXPathElements("Filenames/Filename")) { string key = name + n++.ToString(); //string name = xe2.zExplicitAttributeValue("name"); //string model = xe2.zExplicitAttributeValue("model"); string model = xe2.zAttribValue("model"); if (model != null) { if (!regexModels.ContainsKey(model)) { throw new PBException("unknow filename model \"{0}\"", model); } RegexValuesModel rvm = regexModels[model]; //Dictionary<string, string> attribs = (from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa).zAttribs(); Dictionary <string, string> attribs = new Dictionary <string, string>(); attribs.zAdd(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa); string pattern = rvm.pattern.zSetTextVariables(attribs, true); //Trace.CurrentTrace.WriteLine("\"{0}\" - \"{1}\"", rvm.pattern, pattern); //string values = xe2.zAttribValue("values"); //if (values != null) //{ // if (rvm.values != null && rvm.values != "") // values = rvm.values + ", " + values; //} //else // values = rvm.values; string values = rvm.values; if (values != null) { values = values.zSetTextVariables(attribs, true); } _printRegexList.Add(key, new RegexValues(key, name, pattern, rvm.options, values)); } else { string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zExplicitAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList.Add(key, new RegexValues(key, name, regex, options, values)); } } n = 1; // zElements("Filenames2/Filename") foreach (XElement xe2 in xe.zXPathElements("Filenames2/Filename")) { string key = name + n++.ToString(); string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList2.Add(key, new RegexValues(key, name, regex, options, values)); } } }
private void init(XElement xelement) { _directory = xelement.zXPathValue("Directory"); Dictionary<string, RegexValuesModel> regexModels = new Dictionary<string, RegexValuesModel>(); // zElements("FilenamesModel/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenamesModel/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); regexModels.Add(rvm.key, rvm); } _regexModels = new Dictionary<string, RegexValuesModel>(); // zElements("FilenameModels/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenameModels/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); _regexModels.Add(rvm.key, rvm); } // zElements("FilenameDates/FilenameDate") _dateRegexList = new RegexValuesList(xelement.zXPathElements("FilenameDates/FilenameDate")); //if (_trace) // Trace.CurrentTrace.WriteLine("_dateRegexList {0}", _dateRegexList.Count); _printRegexList = new RegexValuesList(); _printRegexList2 = new RegexValuesList(); _prints = new Dictionary<string, Print1>(); // zElements("Prints/Print") foreach (XElement xe in xelement.zXPathElements("Prints/Print")) { Print1 print = null; switch (xe.zXPathValue("Class")) { case "LeMonde": print = new LeMonde(xe, _directory, _regexModels); break; case "LeParisien": print = new LeParisien(xe, _directory, _regexModels); break; case "LeVifExpress": print = new LeVifExpress(xe, _directory, _regexModels); break; default: print = new Print1(xe, _directory, _regexModels); break; } string name = print.Name; _prints.Add(name, print); int n = 1; // zElements("Filenames/Filename") foreach (XElement xe2 in xe.zXPathElements("Filenames/Filename")) { string key = name + n++.ToString(); //string name = xe2.zExplicitAttributeValue("name"); //string model = xe2.zExplicitAttributeValue("model"); string model = xe2.zAttribValue("model"); if (model != null) { if (!regexModels.ContainsKey(model)) throw new PBException("unknow filename model \"{0}\"", model); RegexValuesModel rvm = regexModels[model]; //Dictionary<string, string> attribs = (from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa).zAttribs(); Dictionary<string, string> attribs = new Dictionary<string, string>(); attribs.zAdd(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa); string pattern = rvm.pattern.zSetTextVariables(attribs, true); //Trace.CurrentTrace.WriteLine("\"{0}\" - \"{1}\"", rvm.pattern, pattern); //string values = xe2.zAttribValue("values"); //if (values != null) //{ // if (rvm.values != null && rvm.values != "") // values = rvm.values + ", " + values; //} //else // values = rvm.values; string values = rvm.values; if (values != null) values = values.zSetTextVariables(attribs, true); _printRegexList.Add(key, new RegexValues(key, name, pattern, rvm.options, values)); } else { string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zExplicitAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList.Add(key, new RegexValues(key, name, regex, options, values)); } } n = 1; // zElements("Filenames2/Filename") foreach (XElement xe2 in xe.zXPathElements("Filenames2/Filename")) { string key = name + n++.ToString(); string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList2.Add(key, new RegexValues(key, name, regex, options, values)); } } }
public static IEnumerable <Response> Read(string file, RegexValuesList regexList, string baseDirectory = null) { return(new ResponseReader { _file = file, _sourceFile = GetSubPath(file, baseDirectory), _regexList = regexList }._Read()); }
public FindDayManager(IEnumerable<XElement> days, bool compileRegex = false) { _dayRegexList = new RegexValuesList(days, compileRegex: compileRegex); }
private void init(XElement xelement) { _directory = xelement.zXPathValue("Directory"); _regexModels = new Dictionary<string, RegexValuesModel>(); // zElements("FilenameInfos/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenameInfos/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); _regexModels.Add(rvm.key, rvm); } // zElements("FilenameInfos/FilenameDate") _dateRegexList = new RegexValuesList(xelement.zXPathElements("FilenameInfos/FilenameDate")); //XElement xe3 = xelement.zXPathElement("FilenameInfos/FilenameDay"); //if (xe3 != null) // _dayRegex = new RegexValues(xe3); // zElements("FilenameInfos/FilenameDay") _dayRegexList = new RegexValuesList(xelement.zXPathElements("FilenameInfos/FilenameDay")); // zElements("FilenameInfos/FilenameNumber") _numberRegexList = new RegexValuesList(xelement.zXPathElements("FilenameInfos/FilenameNumber")); //xe3 = xelement.zXPathElement("FilenameInfos/FilenameSpecial"); //if (xe3 != null) // _specialRegex = new RegexValues(xe3); // zElements("FilenameInfos/FilenameSpecial") _specialRegexList = new RegexValuesList(xelement.zXPathElements("FilenameInfos/FilenameSpecial")); _printRegexList = new RegexValuesList(); _prints = new Dictionary<string, Print>(); // zElements("Prints/Print") foreach (XElement xe in xelement.zXPathElements("Prints/Print")) { Print print = null; switch (xe.zXPathValue("Class")) { case "LeMonde": print = new PrintLeMonde(xe, _directory, _regexModels); break; case "LeParisien": print = new PrintLeParisien(xe, _directory, _regexModels); break; case "LExpress": print = new PrintLExpress(xe, _directory, _regexModels); break; case "LeVifExpress": print = new PrintLeVifExpress(xe, _directory, _regexModels); break; default: print = new Print(xe, _directory, _regexModels); break; } string name = print.Name; _prints.Add(name, print); int n = 1; // zElements("Filename") foreach (XElement xe2 in xe.zXPathElements("Filename")) { string key = name + n++.ToString(); string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList.Add(key, new RegexValues(key, name, regex, options, values)); } } }
public FindDateManager(IEnumerable<XElement> dates, IEnumerable<XElement> digitDates = null, bool compileRegex = false) { _dateRegexList = new RegexValuesList(dates, compileRegex: compileRegex); if (digitDates != null) _digitDateRegexList = new RegexValuesList(digitDates, compileRegex: compileRegex); }
//private bool _extractValuesFromText = true; public PrintTextValuesManager(RegexValuesList textInfoRegexList, Func <string, string> trim = null) { _textInfoRegexList = textInfoRegexList; _trim = trim; }
private void init(XElement xelement) { _directory = xelement.zXPathValue("Directory"); _regexModels = new Dictionary <string, RegexValuesModel>(); // zElements("FilenameInfos/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenameInfos/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); _regexModels.Add(rvm.key, rvm); } // zElements("FilenameInfos/FilenameDate") _dateRegexList = new RegexValuesList(xelement.zXPathElements("FilenameInfos/FilenameDate")); //XElement xe3 = xelement.zXPathElement("FilenameInfos/FilenameDay"); //if (xe3 != null) // _dayRegex = new RegexValues(xe3); // zElements("FilenameInfos/FilenameDay") _dayRegexList = new RegexValuesList(xelement.zXPathElements("FilenameInfos/FilenameDay")); // zElements("FilenameInfos/FilenameNumber") _numberRegexList = new RegexValuesList(xelement.zXPathElements("FilenameInfos/FilenameNumber")); //xe3 = xelement.zXPathElement("FilenameInfos/FilenameSpecial"); //if (xe3 != null) // _specialRegex = new RegexValues(xe3); // zElements("FilenameInfos/FilenameSpecial") _specialRegexList = new RegexValuesList(xelement.zXPathElements("FilenameInfos/FilenameSpecial")); _printRegexList = new RegexValuesList(); _prints = new Dictionary <string, Print>(); // zElements("Prints/Print") foreach (XElement xe in xelement.zXPathElements("Prints/Print")) { Print print = null; switch (xe.zXPathValue("Class")) { case "LeMonde": print = new PrintLeMonde(xe, _directory, _regexModels); break; case "LeParisien": print = new PrintLeParisien(xe, _directory, _regexModels); break; case "LExpress": print = new PrintLExpress(xe, _directory, _regexModels); break; case "LeVifExpress": print = new PrintLeVifExpress(xe, _directory, _regexModels); break; default: print = new Print(xe, _directory, _regexModels); break; } string name = print.Name; _prints.Add(name, print); int n = 1; // zElements("Filename") foreach (XElement xe2 in xe.zXPathElements("Filename")) { string key = name + n++.ToString(); string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList.Add(key, new RegexValues(key, name, regex, options, values)); } } }
public FindDateManager_v1(IEnumerable<XElement> xelements, bool compileRegex = false) { _dateRegexList = new RegexValuesList(xelements, compileRegex: compileRegex); }
public static void Init() { //TelechargementPlus_LoadHeader.ClassInit(XmlConfig.CurrentConfig.GetElement("TelechargementPlus/Header")); _textInfoRegexList = new RegexValuesList(XmlConfig.CurrentConfig.GetElements("TelechargementPlus/TextInfo")); InitImagesToSkip(); }
public static void Test_FindDate_01(RegexValuesList dateRegexList, string file) { file = zPath.Combine(GetDirectoryDate(), file); string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_out"); Trace.WriteLine("Test_FindDate \"{0}\" (nb date regex {1})", file, dateRegexList.Count); //Trace.CurrentTrace.DisableBaseLog(); Trace.CurrentTrace.DisableViewer = true; //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile); Trace.CurrentTrace.AddOnWrite("Test_FindDate_01", WriteToFile.Create(traceFile, FileOption.RazFile).Write); try { TraceRegexValuesList(dateRegexList); Trace.WriteLine(); foreach (BsonDocument document in zmongo.BsonRead<BsonDocument>(file)) FindDate(dateRegexList, document["text"].AsString); } finally { //Trace.CurrentTrace.EnableBaseLog(); //Trace.CurrentTrace.RemoveTraceFile(traceFile); Trace.CurrentTrace.RemoveOnWrite("Test_FindDate_01"); Trace.CurrentTrace.DisableViewer = false; } }
public FindNumberManager(IEnumerable<XElement> xelements, bool compileRegex = false) { _numberRegexList = new RegexValuesList(xelements, compileRegex: compileRegex); }
public static void Test_RegexValues(IEnumerable<XElement> elements, string input) { Trace.WriteLine("\"{0}\" : ", input); RegexValuesList rvs = new RegexValuesList(elements); //FindText_old findText = rvs.Find_old(input); FindText findText = rvs.Find(input); if (findText.Found) { //NamedValues<ZValue> values = findText.regexValues.GetValues_old(); NamedValues<ZValue> values = findText.matchValues.GetValues(); //Trace.WriteLine(" found \"{0}\" {1} values", findText.regexValues.Name, values.Count); Trace.WriteLine(" found \"{0}\" {1} values", findText.matchValues.Name, values.Count); foreach (KeyValuePair<string, ZValue> value in values) { if (value.Value is ZStringArray) Trace.WriteLine(" value {0} = [{1}] {2}", value.Key, ((string[])value.Value).Length, ((string[])value.Value).zToStringValues(s => "\"" + s.zToStringOrNull() + "\"")); else Trace.WriteLine(" value {0} = \"{1}\"", value.Key, value.Value.zToStringOrNull()); } } else Trace.WriteLine(" not found"); Trace.WriteLine(); }
public FindDayManager(IEnumerable <XElement> days, bool compileRegex = false) { _dayRegexList = new RegexValuesList(days, compileRegex: compileRegex); }
// RegexValuesList regexList //public TextDataReader(IEnumerable<string> files) //{ // //_regexList = regexList; // _files = files; //} public void SetRegexList(RegexValuesList regexList) { _regexList = regexList; }