/// <summary> /// /// </summary> private void ResolveTextFilterType() { if (NoSWCheckboxCheckedState == false && STCheckboxCheckedState == false) { txtfilterType = TextFilterType.NoFilter; } else if (NoSWCheckboxCheckedState == true && STCheckboxCheckedState == true) { txtfilterType = TextFilterType.StopwordsRemovalStemming; } else if (NoSWCheckboxCheckedState == true) { txtfilterType = TextFilterType.StopwordsRemoval; } else if (STCheckboxCheckedState == true) { txtfilterType = TextFilterType.Stemming; } }
/// <summary> /// This is the constructor for BOF user reviews. Overloaded Method /// </summary> /// <param name="inputFramesList"></param> public WekaClassifier(List <List <string> > inputBoFList, string trainingFilePath, string directoryName, ClassifierName classificationName, TextFilterType textFilterType) { ConstructFramesArffFile(inputBoFList, directoryName); switch (classificationName) { case ClassifierName.SupportVectorMachine: FilteredSVM("BOF", trainingFilePath, directoryName, textFilterType); break; case ClassifierName.NaiveBayes: FilteredNaiveBayes("BOF", trainingFilePath, directoryName, textFilterType); break; case ClassifierName.RandomForest: break; default: break; } }
/// <summary> /// Filtered Support Vector Machine Classification with type specified. i.e. BOF or BOW /// </summary> /// <param name="type"></param> private void FilteredSVM(string type, string trainingFilePath, string directoryName, TextFilterType textFilterType) { var currDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); // Combine the base folder with your specific folder.... string specificFolder = System.IO.Path.Combine(currDir, "MARC 2.0"); // Check if folder exists and if not, create it if (!Directory.Exists(specificFolder)) { Directory.CreateDirectory(specificFolder); } try { var trainingDatatsetFilePath = ""; if (type == "BOF") { trainingDatatsetFilePath = specificFolder + "\\InputData\\TrainingDatasets\\BOF Dataset.arff"; } else { trainingDatatsetFilePath = specificFolder + "\\InputData\\TrainingDatasets\\BOW Dataset.arff"; } var testDatasetFilePath = specificFolder + "\\InputData\\TrainingDatasets\\Test.arff"; // If training file path is supplied then use it. if (trainingFilePath != null) { trainingDatatsetFilePath = trainingFilePath; } java.io.BufferedReader trainReader = new BufferedReader(new FileReader(trainingDatatsetFilePath)); //File with text examples BufferedReader classifyReader = new BufferedReader(new FileReader(testDatasetFilePath)); //File with text to classify Instances trainInsts = new Instances(trainReader); Instances classifyInsts = new Instances(classifyReader); trainInsts.setClassIndex(trainInsts.numAttributes() - 1); classifyInsts.setClassIndex(classifyInsts.numAttributes() - 1); FilteredClassifier model = new FilteredClassifier(); StringToWordVector stringtowordvector = new StringToWordVector(); stringtowordvector.setTFTransform(true); model.setFilter(new StringToWordVector()); weka.classifiers.Classifier smocls = new weka.classifiers.functions.SMO(); //smocls.setOptions(weka.core.Utils.splitOptions("-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.Puk -C 250007 -O 1.0 -S 1.0\"")); smocls.setOptions(weka.core.Utils.splitOptions("-C 1.0 -L 0.0010 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\"")); model.setClassifier(smocls); bool exists; var directoryRoot = System.IO.Path.GetDirectoryName(Directory.GetCurrentDirectory()); directoryRoot = specificFolder; //Check if the model exists and if not then build a model switch (textFilterType) { case TextFilterType.NoFilter: exists = SVMNoFilterCheckifModelExists(trainingDatatsetFilePath); //if does not exists then build model and save it and save the file also for current filter if (!exists) { model.buildClassifier(trainInsts); Helper.Helper.WriteToBinaryFile <FilteredClassifier>(directoryRoot + @"\Model\SVM\SVMNoFilterModel.dat", model); string content = System.IO.File.ReadAllText(trainingDatatsetFilePath); using (var sW = new StreamWriter(directoryRoot + @"\Model\SVM\\SVMNoFilterFile.dat")) { sW.Write(content); } } // if exists then read the file and use the model else { model = Helper.Helper.ReadFromBinaryFile <FilteredClassifier>(directoryRoot + @"\Model\SVM\SVMNoFilterModel.dat"); } break; //Case Stopwords Removal case TextFilterType.StopwordsRemoval: exists = SVMSWRCheckifModelExists(trainingDatatsetFilePath); //if does not exists then build model and save it and save the file also for current filter if (!exists) { model.buildClassifier(trainInsts); Helper.Helper.WriteToBinaryFile <FilteredClassifier>(directoryRoot + @"\Model\SVM\SVMSWRFilterModel.dat", model); string content = System.IO.File.ReadAllText(trainingDatatsetFilePath); using (var sW = new StreamWriter(directoryRoot + @"\Model\SVM\\SVMSWRFile.dat")) { sW.Write(content); } } // if exists then read the file and use the model else { model = Helper.Helper.ReadFromBinaryFile <FilteredClassifier>(directoryRoot + @"\Model\SVM\SVMSWRFilterModel.dat"); } break; //Case Stemming case TextFilterType.Stemming: exists = SVMSTCheckifModelExists(trainingDatatsetFilePath); //if does not exists then build model and save it and save the file also for current filter if (!exists) { model.buildClassifier(trainInsts); Helper.Helper.WriteToBinaryFile <FilteredClassifier>(directoryRoot + @"\Model\SVM\SVMSTFilterModel.dat", model); string content = System.IO.File.ReadAllText(trainingDatatsetFilePath); using (var sW = new StreamWriter(directoryRoot + @"\Model\SVM\\SVMSTFile.dat")) { sW.Write(content); } } // if exists then read the file and use the model else { model = Helper.Helper.ReadFromBinaryFile <FilteredClassifier>(directoryRoot + @"\Model\SVM\SVMSTFilterModel.dat"); } break; //Case Stopwords Removal with Stemming case TextFilterType.StopwordsRemovalStemming: exists = SVMSWRSTCheckifModelExists(trainingDatatsetFilePath); //if does not exists then build model and save it and save the file also for current filter if (!exists) { model.buildClassifier(trainInsts); Helper.Helper.WriteToBinaryFile <FilteredClassifier>(directoryRoot + @"\Model\SVM\SVMSWRSTFilterModel.dat", model); string content = System.IO.File.ReadAllText(trainingDatatsetFilePath); using (var sW = new StreamWriter(directoryRoot + @"\Model\SVM\\SVMSWRSTFile.dat")) { sW.Write(content); } } // if exists then read the file and use the model else { model = Helper.Helper.ReadFromBinaryFile <FilteredClassifier>(directoryRoot + @"\Model\SVM\SVMSWRSTFilterModel.dat"); } break; default: break; } //model.buildClassifier(trainInsts); for (int i = 0; i < classifyInsts.numInstances(); i++) { classifyInsts.instance(i).setClassMissing(); double cls = model.classifyInstance(classifyInsts.instance(i)); classifyInsts.instance(i).setClassValue(cls); classification = cls == 0 ? "Bug Report" : cls == 1 ? "Feature Request" : "Other"; tempAllClassification.Add(classification); } AllClassification = tempAllClassification; } catch (Exception o) { error = o.ToString(); } }
public StringQuery(string value, TextFilterType filterType) { _value = value; _filterType = filterType; }
void LoadFile() { FileInfo f = new FileInfo(fileName); fileSubList = null; // Create the LM branch for the file... foreach (RenderableObject l in layer.ChildObjects) { if (l.Name == f.Name) { fileSubList = (RenderableObjectList)l; break; } } if (fileSubList == null) { fileSubList = new RenderableObjectList(f.Name); } layer.Add(fileSubList); ogr.UseExceptions(); try { ogr.RegisterAll(); ds = ogr.Open(fileName, 0); ogrLayer = ds.GetLayerByIndex(0); SpatialReference inSrs = ogrLayer.GetSpatialRef(); ArrayList fieldNames = GetFieldNames(ogrLayer); infoSelector = new VectorInfoSelector(ogrLayer); if (infoSelector.ShowDialog() != DialogResult.OK) { return; } styleSubList = new RenderableObjectList(infoSelector.TextStyle.Layername); styleSubList.IsOn = false; fileSubList.Add(styleSubList); keyFieldName = infoSelector.TextStyle.KeyDataFieldName; keyDataType = infoSelector.TextStyle.DataType; labelFieldName = infoSelector.TextStyle.LabelFieldName; if (keyDataType == DataType.Text && infoSelector.TextStyle.TextFilter) { filterString = infoSelector.TextStyle.TextFilterString; textFilterType = infoSelector.TextStyle.TextFilterType; } maxPolygonColor = infoSelector.NumericMaxStyle.PolygonColor; maxLineColor = infoSelector.NumericMaxStyle.LineColor; maxLineWidth = infoSelector.NumericMaxStyle.LineWidth; maxOutlinePolygons = infoSelector.NumericMaxStyle.OutlinePolygons; minPolygonColor = infoSelector.NumericMinStyle.PolygonColor; minLineColor = infoSelector.NumericMinStyle.LineColor; minLineWidth = infoSelector.NumericMinStyle.LineWidth; minOutlinePolygons = infoSelector.NumericMinStyle.OutlinePolygons; noDataLineColor = infoSelector.NumericNoDataStyle.LineColor; noDataLineWidth = infoSelector.NumericNoDataStyle.LineWidth; noDataPolygonColor = infoSelector.NumericNoDataStyle.PolygonColor; noDataOutlinePolygons = infoSelector.NumericNoDataStyle.OutlinePolygons; noDataValue = infoSelector.NumericNoDataStyle.NoDataValue; textLineColor = infoSelector.TextStyle.LineColor; textLineWidth = infoSelector.TextStyle.LineWidth; textPolygonColor = infoSelector.TextStyle.PolygonColor; textOutlinePolygons = infoSelector.TextStyle.OutlinePolygons; if (infoSelector.Projection.Contains("EPSG")) { string trimString = "EPSG:"; string epsgString = infoSelector.Projection.Trim(trimString.ToCharArray()); int epsg = int.Parse(epsgString); inSrs = new SpatialReference(""); inSrs.ImportFromEPSG(epsg); } else if (infoSelector.Projection == "" || infoSelector.Projection == "(unknown)") { inSrs = null; } else { inSrs = new SpatialReference(""); inSrs.ImportFromProj4(infoSelector.Projection); } OGR.SpatialReference outSrs = new OGR.SpatialReference(outWkt); //outSrs.ImportFromEPSG(4326); if (inSrs != null) { coordTransform = new CoordinateTransformation(inSrs, outSrs); needsTransformation = true; Console.WriteLine("Reprojecting..."); } keyFieldIndex = GetFieldIndexFromString(keyFieldName, fieldNames); labelFieldIndex = GetFieldIndexFromString(labelFieldName, fieldNames); } catch (Exception ex) { MessageBox.Show(ex.Message + "\nNo features imported."); return; } Thread t = new Thread(new System.Threading.ThreadStart(LoadVectors)); t.IsBackground = true; t.Start(); }