Beispiel #1
0
        private static SearchItem CreateSearchItemFromPropertyNode(XmlNode node, string proposedType)
        {
            SearchItem res  = null;
            var        irdi = EclassUtils.GetAttributeByName(node, "id");

            if (irdi == null)
            {
                irdi = EclassUtils.GetAttributeByName(node, "xml:id");
            }
            if (irdi != null)
            {
                var info = "";
                if (node.Name == "ontoml:property" && node.HasChildNodes)
                {
                    var n2 = node.SelectSingleNode("preferred_name");
                    if (n2 != null && n2.HasChildNodes)
                    {
                        foreach (var c2 in n2.ChildNodes)
                        {
                            if (c2 is XmlNode && (c2 as XmlNode).Name == "label")
                            {
                                info = (c2 as XmlNode).InnerText;
                            }
                        }
                    }
                    proposedType = "prop";
                }
                res = new SearchItem(proposedType, irdi, info, node);
            }
            return(res);
        }
Beispiel #2
0
        private bool FinalizeSelection()
        {
            // get the IRDI
            var si = EntityList.SelectedItem as EclassUtils.SearchItem;

            if (si == null)
            {
                return(false);
            }

            // simply put the IRDI
            this.ResultIRDI = si.IRDI;

            // special case: property selected
            if (si.Entity == "prop")
            {
                var input = new List <EclassUtils.SearchItem>();
                input.Add(si);
                foreach (EclassUtils.SearchItem di in EntityList.Items)
                {
                    if (di != null && di.Entity == si.Entity && di.IRDI == si.IRDI && si != di)
                    {
                        input.Add(di);
                    }
                }

                // own function
                this.ResultCD = EclassUtils.GenerateConceptDescription(input, si.IRDI);
            }

            // ok
            return(true);
        }
Beispiel #3
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            // run all background tasks here
            var a = e.Argument as BackgroundWorkerArgs;

            if (a?.jobData != null && a.jobType == 1)
            {
                EclassUtils.SearchForTextInEclassFiles(a.jobData, (frac) =>
                {
                    SearchProgress.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Background,
                        new Action(() => this.SearchProgress.Value = frac));
                });
            }

            if (a?.jobData != null && a.jobType == 2)
            {
                EclassUtils.SearchForIRDIinEclassFiles(a.jobData, (frac) =>
                {
                    SearchProgress.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Background,
                        new Action(() => this.SearchProgress.Value = frac));
                });
            }

            // set result
            e.Result = e.Argument;
        }
Beispiel #4
0
 public SearchJobData(string eclassFullPath)
 {
     if (eclassFullPath == null || eclassFullPath == "")
     {
         return;
     }
     foreach (var fn in System.IO.Directory.GetFiles(eclassFullPath, "*.xml"))
     {
         var dft = EclassUtils.TryGetDataFileType(fn);
         eclassFiles.Add(new EclassUtils.FileItem(fn, dft));
     }
 }
Beispiel #5
0
        private EclassUtils.SearchJobData InitJobData()
        {
            var args = new EclassUtils.SearchJobData();

            args.searchInClasses    = this.SearchInClasses.IsChecked == true;
            args.searchInDatatypes  = this.SearchInDatatypes.IsChecked == true;
            args.searchInProperties = this.SearchInProperties.IsChecked == true;
            args.searchInUnits      = this.SearchInUnits.IsChecked == true;

            args.eclassFiles.Clear();
            foreach (var fn in System.IO.Directory.GetFiles(eclassFullPath, "*.xml"))
            {
                var dft = EclassUtils.TryGetDataFileType(fn);
                args.eclassFiles.Add(new EclassUtils.FileItem(fn, dft));
            }

            return(args);
        }
Beispiel #6
0
        private void ButtonSelect_Click(object sender, RoutedEventArgs e)
        {
            if (CheckBoxTwoPass.IsChecked != true)
            {
                // trivial case, take directly
                if (FinalizeSelection())
                {
                    this.DialogResult = true;
                }
                return;
            }

            // OK, search for IRDI first
            var si = EntityList.SelectedItem as EclassUtils.SearchItem;

            if (si != null && si.Entity == "prop" && si.ContentNode != null)
            {
                var irdi = EclassUtils.GetAttributeByName(si.ContentNode, "id");
                if (irdi != null)
                {
                    if (!worker.IsBusy && eclassFullPath != null)
                    {
                        SearchProgress.Value = 0;
                        EntityList.Items.Clear();
                        EntityContent.Text = "";

                        var args = new BackgroundWorkerArgs();
                        args.jobData = InitJobData();
                        args.jobData.searchIRDIs.Add(irdi.Trim().ToLower());
                        args.jobType = 2;

                        worker.RunWorkerAsync(args);
                    }
                }
            }
        }
Beispiel #7
0
        private void worker_RunWorkerCompleted(object sender,
                                               RunWorkerCompletedEventArgs e)
        {
            //update ui once worker complete his work
            SearchProgress.Value = 100;

            // access
            var a = (e.Result as BackgroundWorkerArgs);

            if (a == null)
            {
                return;
            }

            // search text!
            if (a.jobType == 1)
            {
                // may be inform upon too many elements
                if (a.jobData.tooMany)
                {
                    MessageBox.Show(
                        this,
                        "Too many search result. Search aborted!", "Search entities",
                        MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }

                // sort
                a.jobData.items.Sort(delegate(EclassUtils.SearchItem si1, EclassUtils.SearchItem si2)
                {
                    if (si1.Entity != si2.Entity)
                    {
                        return(String.Compare(si1.Entity, si2.Entity, StringComparison.Ordinal));
                    }
                    else
                    {
                        return(String.Compare(si1.IRDI, si2.IRDI, StringComparison.Ordinal));
                    }
                });

                // re-fill into the UI list
                EntityList.Items.Clear();
                foreach (var it in a.jobData.items)
                {
                    EntityList.Items.Add(it);
                }
            }

            if (a.jobType == 2 && a.jobData != null && a.jobData.searchIRDIs.Count == 1)
            {
                // 1st pass already done, the jobData items already containing all required information to
                // generate a proper content description

                // own function
                var resIrdi = a.jobData.searchIRDIs[0].ToUpper();
                this.ResultCD   = EclassUtils.GenerateConceptDescription(a.jobData.items, resIrdi);
                this.ResultIRDI = resIrdi;

                // success -> auto close
                if (this.ResultCD != null)
                {
                    this.DialogResult = true;
                }
            }
        }
        private bool FinalizeSelection(EclassUtils.SearchItem si, bool twoPass)
        {
            // access
            if (si == null)
            {
                return(false);
            }

            // simply put the IRDI
            DiaData.ResultIRDI = si.IRDI;

            // special case: unit .. try correct from unit id to unitCodeValue for IRDI
            if (si.Entity == "unit")
            {
                var x = EclassUtils.GetIrdiForUnitSearchItem(si);
                if (x != null)
                {
                    DiaData.ResultIRDI = x;
                }
            }

            // one or two passes?
            if (!twoPass)
            {
                // special case: property selected
                if (si.Entity == "prop" && DiaData.Mode != AnyUiDialogueDataSelectEclassEntity.SelectMode.IRDI)
                {
                    var input = new List <EclassUtils.SearchItem>();
                    input.Add(si);
                    foreach (EclassUtils.SearchItem di in EntityList.Items)
                    {
                        if (di != null && di.Entity == si.Entity && di.IRDI == si.IRDI && si != di)
                        {
                            input.Add(di);
                        }
                    }

                    // own function
                    DiaData.ResultCD = EclassUtils.GenerateConceptDescription(input, si.IRDI);
                }
            }
            else
            {
                if (si.Entity == "prop" && si.ContentNode != null)
                {
                    var irdi = EclassUtils.GetAttributeByName(si.ContentNode, "id");
                    if (irdi != null)
                    {
                        if (!worker.IsBusy && eclassFullPath != null)
                        {
                            SearchProgress.Value = 0;
                            EntityList.Items.Clear();
                            EntityContent.Text = "";

                            var args = new BackgroundWorkerArgs();
                            args.jobData = InitJobData();
                            args.jobData.searchIRDIs.Add(irdi.Trim().ToLower());
                            args.jobType = 2;

                            // start second pass!
                            worker.RunWorkerAsync(args);
                            return(false);
                        }
                    }
                }
            }

            // generally ok
            return(true);
        }