/// <summary>
 /// Common Predicates between all the resources we're comparing
 /// </summary>
 /// <returns>list<predURI,predLabel></returns>
 public List<KeyValuePair<string, string>> getCommonPredicates(ResourceInformation ri)
 {
     List<KeyValuePair<string, string>> toReturn = new List<KeyValuePair<string, string>>();
     foreach (KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>> item in ri.FinalComparisonObject)
     {
         toReturn.Add(item.Key);
     }
     return toReturn;
 }
Example #2
0
        /// <summary>
        /// Common Predicates between all the resources we're comparing
        /// </summary>
        /// <returns>list<predURI,predLabel></returns>
        public List <KeyValuePair <string, string> > getCommonPredicates(ResourceInformation ri)
        {
            List <KeyValuePair <string, string> > toReturn = new List <KeyValuePair <string, string> >();

            foreach (KeyValuePair <KeyValuePair <string, string>, List <KeyValuePair <string, string> > > item in ri.FinalComparisonObject)
            {
                toReturn.Add(item.Key);
            }
            return(toReturn);
        }
 /// <summary>
 /// gets List of resources of a certain predicate
 /// </summary>
 /// <param name="pred">the predicate as a keyValuePair</param>
 /// <returns>the resources attached as a list of keyValuePairs</returns>
 public List<KeyValuePair<string, string>> getResourcesOfPredicate(KeyValuePair<string, string> pred, ResourceInformation ri)
 {
     foreach (KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>> item in ri.rawComparisonObject)
     {
         if (item.Key.Equals(pred))
             return item.Value;
     }
     //if not foud
     return null;
 }
Example #4
0
        /// <summary>
        /// Fills The comparisonComponent of each Resource To compare
        /// </summary>
        /// <param name="input">Object to fill its rawComparisonObject</param>
        /// <returns>The same resource Again</returns>
        public ResourceInformation fillComparisonComponent(ResourceInformation input)
        {
            var q = from x in input.predicates_resourceIsSubj
                    group x by x into g
                    let count = g.Count()
                    //orderby count descending
                    select new { Value = g.Key, Count = count };

            int counter = 0;
            foreach (var x in q)
            {
                List<KeyValuePair<string, string>> tempRes = new List<KeyValuePair<string, string>>();
                KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>> temp = new KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>();
                KeyValuePair<string, string> predicates= new KeyValuePair<string, string>();
                predicates = x.Value;
                for (int i = counter; i < counter+x.Count; i++)
                {
                    tempRes.Add(input.resources_resourceIsSubj[i]);
                }
                temp = new KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>(predicates, tempRes);
                input.rawComparisonObject.Add(temp);
                //Console.WriteLine("Value: " + x.Value + " Count: " + x.Count);
                counter += x.Count;
            }

            /////////
            var q2 = from x in input.predicates_resourceIsObj
                    group x by x into g
                    let count = g.Count()
                    //orderby count descending
                    select new { Value = g.Key, Count = count };

            counter = 0;
            foreach (var x in q2)
            {
                List<KeyValuePair<string, string>> tempRes = new List<KeyValuePair<string, string>>();
                KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>> temp = new KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>();
                KeyValuePair<string, string> predicates = new KeyValuePair<string, string>();
                predicates = x.Value;
                for (int i = counter; i < counter + x.Count; i++)
                {
                    tempRes.Add(input.resources_resourceIsObj[i]);
                }
                temp = new KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>(predicates, tempRes);
                input.rawComparisonObject.Add(temp);
                //Console.WriteLine("Value: " + x.Value + " Count: " + x.Count);
            }
            /////////
            return input;
        }
Example #5
0
        public void getData(List <string> Input_URIs, List <string> PredicatesToExclude)
        {
            //Generating filter string to add to the queries
            string excluded = "";

            if (PredicatesToExclude.Count > 0)
            {
                for (int i = 0; i < PredicatesToExclude.Count; i++)
                {
                    excluded += ". filter (?pred != <" + PredicatesToExclude[i] + ">)";
                }
            }


            //should be returned
            List <ResourceInformation> ResourceInformationList = new List <ResourceInformation>();

            foreach (string item in Input_URIs)
            {
                //constructing the queries, we had to do FROM<dbpedia.org> to prevent garbage data, should be faster too
                string querySide1 = "SELECT *  WHERE {<" + item + "> ?pred ?obj" + excluded + "}";
                string querySide2 = "SELECT *  WHERE {?subj ?pred <" + item + ">" + excluded + "}";


                //doing both queries
                SparqlResultSet res1 = new SparqlResultSet();
                SparqlResultSet res2 = new SparqlResultSet();
                //res1 = endpoint.QueryWithResultSet(querySide1);
                //res2 = endpoint.QueryWithResultSet(querySide2);

                res1 = Request.RequestWithHTTP(querySide1);
                res2 = Request.RequestWithHTTP(querySide2);



                //Initialize the resource
                ResourceInformation temp = new ResourceInformation();
                temp.predicates_resourceIsSubj = new List <KeyValuePair <string, string> >();
                temp.resources_resourceIsSubj  = new List <KeyValuePair <string, string> >();
                temp.predicates_resourceIsObj  = new List <KeyValuePair <string, string> >();
                temp.resources_resourceIsObj   = new List <KeyValuePair <string, string> >();
                temp.rawComparisonObject       = new List <KeyValuePair <KeyValuePair <string, string>, List <KeyValuePair <string, string> > > >();
                temp.FinalComparisonObject     = new List <KeyValuePair <KeyValuePair <string, string>, List <KeyValuePair <string, string> > > >();
                temp.ID = new KeyValuePair <string, string>();

                //Filling all the information in case  <ourResourceID> ?x ?y
                foreach (SparqlResult item_res1 in res1)
                {
                    //string tempo=getLabel(((LiteralNode)item_res1.Value("pred")).ToString());
                    if (String.Equals(((INode)(item_res1.Value("obj"))).GetType().Name.ToString(), "UriNode"))
                    {
                        temp.resources_resourceIsSubj.Add(new KeyValuePair <string, string>(item_res1.Value("obj").ToString(), util.getLabel(item_res1.Value("obj").ToString())));
                    }
                    else
                    {
                        string onlyValue = ((LiteralNode)item_res1.Value("obj")).Value;
                        temp.resources_resourceIsSubj.Add(new KeyValuePair <string, string>(item_res1.Value("obj").ToString(), onlyValue));

                        //To fill out the ID component
                        if (String.Equals(item_res1.Value("pred").ToString(), "http://www.w3.org/2000/01/rdf-schema#label"))
                        {
                            temp.ID = new KeyValuePair <string, string>(item, temp.resources_resourceIsSubj[temp.resources_resourceIsSubj.Count - 1].Value);
                        }
                    }

                    temp.predicates_resourceIsSubj.Add(new KeyValuePair <string, string>(item_res1.Value("pred").ToString(), util.getLabel(item_res1.Value("pred").ToString())));
                }

                //Filling all the information in case ?x ?y <ourResourceID>
                foreach (SparqlResult item_res2 in res2)
                {
                    //We add of to the name, child of .....etc
                    temp.predicates_resourceIsObj.Add(new KeyValuePair <string, string>(item_res2.Value("pred").ToString(), util.getLabel(item_res2.Value("pred").ToString()) + " of"));

                    if (String.Equals(((INode)(item_res2.Value("subj"))).GetType().Name.ToString(), "UriNode"))
                    {
                        temp.resources_resourceIsObj.Add(new KeyValuePair <string, string>(item_res2.Value("subj").ToString(), util.getLabel(item_res2.Value("subj").ToString())));
                    }
                    else
                    {
                        string onlyValue = ((LiteralNode)item_res2.Value("subj")).Value;
                        temp.resources_resourceIsSubj.Add(new KeyValuePair <string, string>(item_res2.Value("subj").ToString(), onlyValue));
                    }
                }

                //filling comparison component
                temp = fillComparisonComponent(temp);

                //Addding the resource to the list of resourceInformation Objects
                ResourceInformationList.Add(temp);

                //Copying it to the globalVariable
                ComparisonOutput = ResourceInformationList;
            }
            //getting common between URIs
            //Console.WriteLine("getting Common");
            ResourceInformationList = getCommon(ResourceInformationList);


            //logging
            //logResults(ResourceInformationList);
        }
Example #6
0
        /// <summary>
        /// Fills The comparisonComponent of each Resource To compare
        /// </summary>
        /// <param name="input">Object to fill its rawComparisonObject</param>
        /// <returns>The same resource Again</returns>
        public ResourceInformation fillComparisonComponent(ResourceInformation input)
        {
            //we have to make sure the resource information is not empty
            if (input.resources_resourceIsSubj.Count > 1)
            {
                //temp to fill in
                List <KeyValuePair <string, string> > tempList = new List <KeyValuePair <string, string> >();
                KeyValuePair <string, string>         tempPred;

                tempPred = input.predicates_resourceIsSubj[0];
                tempList.Add(input.resources_resourceIsSubj[0]);
                for (int i = 1; i < input.predicates_resourceIsSubj.Count; i++)
                {
                    if (input.predicates_resourceIsSubj[i].Equals(tempPred))
                    {
                        if (tempList.Count < 50)
                        {
                            KeyValuePair <string, string> temp = new KeyValuePair <string, string>(util.encodeURI(input.resources_resourceIsSubj[i].Key), input.resources_resourceIsSubj[i].Value);
                            tempList.Add(temp);
                        }
                    }
                    else
                    {
                        input.rawComparisonObject.Add(new KeyValuePair <KeyValuePair <string, string>, List <KeyValuePair <string, string> > >(tempPred, tempList));
                        tempPred = input.predicates_resourceIsSubj[i];
                        tempList = new List <KeyValuePair <string, string> >();

                        KeyValuePair <string, string> temp = new KeyValuePair <string, string>(util.encodeURI(input.resources_resourceIsSubj[i].Key), input.resources_resourceIsSubj[i].Value);
                        tempList.Add(temp);
                    }
                }

                input.rawComparisonObject.Add(new KeyValuePair <KeyValuePair <string, string>, List <KeyValuePair <string, string> > >(tempPred, tempList));
            }
            if (input.resources_resourceIsObj.Count > 1)
            {
                //temp to fill in
                List <KeyValuePair <string, string> > tempList = new List <KeyValuePair <string, string> >();
                KeyValuePair <string, string>         tempPred;

                tempPred = input.predicates_resourceIsObj[0];
                tempList.Add(input.resources_resourceIsObj[0]);
                for (int i = 1; i < input.predicates_resourceIsObj.Count; i++)
                {
                    if (input.predicates_resourceIsObj[i].Equals(tempPred))
                    {
                        if (tempList.Count < 50)
                        {
                            KeyValuePair <string, string> temp = new KeyValuePair <string, string>(util.encodeURI(input.resources_resourceIsObj[i].Key), input.resources_resourceIsObj[i].Value);
                            tempList.Add(temp);
                        }
                    }
                    else
                    {
                        input.rawComparisonObject.Add(new KeyValuePair <KeyValuePair <string, string>, List <KeyValuePair <string, string> > >(tempPred, tempList.Distinct().ToList()));
                        tempPred = input.predicates_resourceIsObj[i];
                        tempList = new List <KeyValuePair <string, string> >();

                        KeyValuePair <string, string> temp = new KeyValuePair <string, string>(util.encodeURI(input.resources_resourceIsObj[i].Key), input.resources_resourceIsObj[i].Value);
                        tempList.Add(temp);
                    }
                }

                input.rawComparisonObject.Add(new KeyValuePair <KeyValuePair <string, string>, List <KeyValuePair <string, string> > >(tempPred, tempList.Distinct().ToList()));
            }
            //removing duplicates
            for (int i = 0; i < input.rawComparisonObject.Count; i++)
            {
                for (int j = i + 1; j < input.rawComparisonObject.Count; j++)
                {
                    if (input.rawComparisonObject[i].Key.Value.Equals(input.rawComparisonObject[j].Key.Value))
                    {
                        //we remove the one with the smallest resources
                        int indexofremoval = input.rawComparisonObject[i].Value.Count < input.rawComparisonObject[j].Value.Count ? i : j;
                        input.rawComparisonObject.RemoveAt(indexofremoval);
                    }
                }
            }


            return(input);
        }
Example #7
0
 /// <summary>
 /// gets List of resources of a certain predicate
 /// </summary>
 /// <param name="pred">the predicate as a keyValuePair</param>
 /// <returns>the resources attached as a list of keyValuePairs</returns>
 public List <KeyValuePair <string, string> > getResourcesOfPredicate(KeyValuePair <string, string> pred, ResourceInformation ri)
 {
     foreach (KeyValuePair <KeyValuePair <string, string>, List <KeyValuePair <string, string> > > item in ri.rawComparisonObject)
     {
         if (item.Key.Equals(pred))
         {
             return(item.Value);
         }
     }
     //if not foud
     return(null);
 }
Example #8
0
 /// <summary>
 /// gets all predicates responds to the query ?subj ?pred < resource>
 /// </summary>
 /// <returns>list<predURI,predLabel> </returns>
 public List <KeyValuePair <string, string> > getPredicates_ResourceIsObj(ResourceInformation ri)
 {
     return(ri.predicates_resourceIsObj.Distinct().ToList());
 }
Example #9
0
 /// <summary>
 /// gets the id of the resource
 /// </summary>
 /// <returns>uri, label of the id</returns>
 public KeyValuePair <string, string> getID(ResourceInformation ri)
 {
     return(ri.ID);
 }
Example #10
0
        public void getData(List<string> Input_URIs)
        {
            //should be returned
            List<ResourceInformation> ResourceInformationList = new List<ResourceInformation>();
            foreach (string item in Input_URIs)
            {
                //constructing the queries, we had to do FROM<dbpedia.org> to prevent garbage data, should be faster too
                string querySide1 = "SELECT * FROM <http://dbpedia.org> WHERE {<" + item + "> ?pred ?obj}";
                string querySide2 = "SELECT * FROM <http://dbpedia.org> WHERE {?subj ?pred <" + item + ">}";

                //doing both queries
                SparqlResultSet res1 = new SparqlResultSet();
                SparqlResultSet res2 = new SparqlResultSet();
                //res1 = endpoint.QueryWithResultSet(querySide1);
                //res2 = endpoint.QueryWithResultSet(querySide2);

                res1 = Request.RequestWithHTTP(querySide1);
                res2 = Request.RequestWithHTTP(querySide2);

                //Initialize the resource
                ResourceInformation temp = new ResourceInformation();
                temp.predicates_resourceIsSubj = new List<KeyValuePair<string, string>>();
                temp.resources_resourceIsSubj = new List<KeyValuePair<string, string>>();
                temp.predicates_resourceIsObj = new List<KeyValuePair<string, string>>();
                temp.resources_resourceIsObj = new List<KeyValuePair<string, string>>();
                temp.rawComparisonObject = new List<KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>>();
                temp.FinalComparisonObject = new List<KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>>();
                temp.ID = new KeyValuePair<string, string>();

                //Filling all the information in case  <ourResourceID> ?x ?y
                foreach (SparqlResult item_res1 in res1)
                {
                    //string tempo=getLabel(((LiteralNode)item_res1.Value("pred")).ToString());
                    if (String.Equals(((INode)(item_res1.Value("obj"))).GetType().Name.ToString(), "UriNode"))
                    {
                        temp.resources_resourceIsSubj.Add(new KeyValuePair<string, string>(item_res1.Value("obj").ToString(), util.getLabel(item_res1.Value("obj").ToString())));

                    }
                    else
                    {
                        string onlyValue = ((LiteralNode)item_res1.Value("obj")).Value;
                        temp.resources_resourceIsSubj.Add(new KeyValuePair<string, string>(item_res1.Value("obj").ToString(), onlyValue));

                        //To fill out the ID component
                        if (String.Equals(item_res1.Value("pred").ToString(), "http://www.w3.org/2000/01/rdf-schema#label"))
                        {
                            temp.ID = new KeyValuePair<string, string>(item, temp.resources_resourceIsSubj[temp.resources_resourceIsSubj.Count - 1].Value);
                        }
                    }

                    temp.predicates_resourceIsSubj.Add(new KeyValuePair<string, string>(item_res1.Value("pred").ToString(), util.getLabel(item_res1.Value("pred").ToString())));

                }

                //Filling all the information in case ?x ?y <ourResourceID>
                foreach (SparqlResult item_res2 in res2)
                {
                    //We add of to the name, child of .....etc
                    temp.predicates_resourceIsObj.Add(new KeyValuePair<string, string>(item_res2.Value("pred").ToString(), util.getLabel(item_res2.Value("pred").ToString()) + " of"));

                    if (String.Equals(((INode)(item_res2.Value("subj"))).GetType().Name.ToString(), "UriNode"))
                        temp.resources_resourceIsObj.Add(new KeyValuePair<string, string>(item_res2.Value("subj").ToString(), util.getLabel(item_res2.Value("subj").ToString())));
                    else
                    {
                        string onlyValue = ((LiteralNode)item_res2.Value("subj")).Value;
                        temp.resources_resourceIsSubj.Add(new KeyValuePair<string, string>(item_res2.Value("subj").ToString(), onlyValue));
                    }

                }

                //filling comparison component
                temp=fillComparisonComponent(temp);

                //Addding the resource to the list of resourceInformation Objects
                ResourceInformationList.Add(temp);

                //Copying it to the globalVariable
                ComparisonOutput = ResourceInformationList;

            }
            //getting common between URIs
            //Console.WriteLine("getting Common");
            ResourceInformationList=getCommon(ResourceInformationList);

            //logging
            //logResults(ResourceInformationList);
        }
 /// <summary>
 /// gets all predicates responds to the query < resource> ?pred ?obj
 /// </summary>
 /// <returns>list<predURI,predLabel> </returns>
 public List<KeyValuePair<string, string>> getPredicates_ResourceIsSubj(ResourceInformation ri)
 {
     return ri.predicates_resourceIsSubj.Distinct().ToList();
 }
 /// <summary>
 /// gets the id of the resource
 /// </summary>
 /// <returns>uri, label of the id</returns>
 public KeyValuePair<string, string> getID(ResourceInformation ri)
 {
     return ri.ID;
 }
Example #13
0
        /// <summary>
        /// Fills The comparisonComponent of each Resource To compare
        /// </summary>
        /// <param name="input">Object to fill its rawComparisonObject</param>
        /// <returns>The same resource Again</returns>
        public ResourceInformation fillComparisonComponent(ResourceInformation input)
        {
            //we have to make sure the resource information is not empty
            if (input.resources_resourceIsSubj.Count > 1)
            {
                //temp to fill in
                List<KeyValuePair<string, string>> tempList = new List<KeyValuePair<string, string>>();
                KeyValuePair<string, string> tempPred;

                tempPred = input.predicates_resourceIsSubj[0];
                tempList.Add(input.resources_resourceIsSubj[0]);
                for (int i = 1; i < input.predicates_resourceIsSubj.Count; i++)
                {
                    if (input.predicates_resourceIsSubj[i].Equals(tempPred))
                    {
                        if (tempList.Count < 50)
                        {
                            KeyValuePair<string, string> temp = new KeyValuePair<string, string>(util.encodeURI(input.resources_resourceIsSubj[i].Key), input.resources_resourceIsSubj[i].Value);
                            tempList.Add(temp);
                        }
                    }
                    else
                    {
                        input.rawComparisonObject.Add(new KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>(tempPred, tempList));
                        tempPred = input.predicates_resourceIsSubj[i];
                        tempList = new List<KeyValuePair<string, string>>();

                        KeyValuePair<string, string> temp = new KeyValuePair<string, string>(util.encodeURI(input.resources_resourceIsSubj[i].Key), input.resources_resourceIsSubj[i].Value);
                        tempList.Add(temp);
                    }
                }

                input.rawComparisonObject.Add(new KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>(tempPred, tempList));

            }
            if (input.resources_resourceIsObj.Count > 1)
            {
                //temp to fill in
                List<KeyValuePair<string, string>> tempList = new List<KeyValuePair<string, string>>();
                KeyValuePair<string, string> tempPred;

                tempPred = input.predicates_resourceIsObj[0];
                tempList.Add(input.resources_resourceIsObj[0]);
                for (int i = 1; i < input.predicates_resourceIsObj.Count; i++)
                {

                    if (input.predicates_resourceIsObj[i].Equals(tempPred))
                    {
                        if (tempList.Count < 50)
                        {
                            KeyValuePair<string, string> temp = new KeyValuePair<string, string>(util.encodeURI(input.resources_resourceIsObj[i].Key), input.resources_resourceIsObj[i].Value);
                            tempList.Add(temp);
                        }
                    }
                    else
                    {
                        input.rawComparisonObject.Add(new KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>(tempPred, tempList.Distinct().ToList()));
                        tempPred = input.predicates_resourceIsObj[i];
                        tempList = new List<KeyValuePair<string, string>>();

                        KeyValuePair<string, string> temp = new KeyValuePair<string, string>(util.encodeURI(input.resources_resourceIsObj[i].Key), input.resources_resourceIsObj[i].Value);
                        tempList.Add(temp);
                    }
                }

                input.rawComparisonObject.Add(new KeyValuePair<KeyValuePair<string, string>, List<KeyValuePair<string, string>>>(tempPred, tempList.Distinct().ToList()));

            }
            //removing duplicates
            for (int i = 0; i < input.rawComparisonObject.Count; i++)
            {
                for (int j = i + 1; j < input.rawComparisonObject.Count; j++)
                {
                    if (input.rawComparisonObject[i].Key.Value.Equals(input.rawComparisonObject[j].Key.Value))
                    {
                        //we remove the one with the smallest resources
                        int indexofremoval = input.rawComparisonObject[i].Value.Count < input.rawComparisonObject[j].Value.Count ? i : j;
                        input.rawComparisonObject.RemoveAt(indexofremoval);
                    }
                }
            }

            return input;
        }