Example #1
0
        public void ComplexEmbeddedObjectUsage()
        {
            var readService = FreebaseServices.CreateMqlReadService();

            dynamic director = new ExpandoObject();

            director.name = null;
            director.id   = null;
            director.type = "/film/editor";
            director.film = new Dictionary <Object, Object>()
            {
                { "name", null },
                { "id", null },
                { "starring", new Dictionary <Object, Object>()
                  {
                      { "actor", "Theresa Russell" }
                  } }
            };


            MqlReadServiceResponse result = readService.ReadAsync(director);

            //Process result
            var content = result.ResultAsString;
            //get status
            var status = result.Status;
        }
Example #2
0
        public void SimpleUsage()
        {
            var readService = FreebaseServices.CreateMqlReadService();

            dynamic thepolice = new ExpandoObject();

            thepolice.type = "/music/artist";
            thepolice.name = FreebaseHelpers.Operators.CreateLikeOperator("^The Sco*$"); // Regex search

            MqlReadServiceResponse result = readService.ReadAsync(thepolice);

            //Process result
            var content = result.ResultAsString;
            //get status
            var status = result.Status;
        }
Example #3
0
        public void DictionaryUsage()
        {
            var readService = FreebaseServices.CreateMqlReadService();

            dynamic thepolice = new ExpandoObject();

            thepolice.type  = "/music/artist";
            thepolice.name  = "The Scorpions";
            thepolice.album = new Dictionary <Object, Object>();
            thepolice.album.Add("name", null);
            thepolice.album.Add("limit", 2);
            thepolice.album.Add("genre", FreebaseHelpers.CreateArrayWithEmptyObject());


            MqlReadServiceResponse result = readService.ReadAsync(thepolice);

            //Process result
            var content = result.ResultAsString;
            //get status
            var status = result.Status;
        }
Example #4
0
        public void identifyAttributes(Types type)
        {
            var query = new ExpandoObject() as IDictionary<string, Object>;
            query.Add("type", type.FreebaseName);
            query.Add("id", id);

            //Add the linked attributes of othis type to the query
            foreach(Attributes attribute in type.Attributes)
            {
                if (attribute.resultType == "1")
                    query.Add(attribute.FreebaseName.Trim(), null);

                else if (attribute.resultType == "2")
                {
                    query.Add(attribute.FreebaseName.Trim(), new Dictionary<Object, Object>() {
                                                        {"name",null}
                                                       });
                }
            }

            // create mqlresult
            this.mqlReadService = FreebaseServices.CreateMqlReadService();
            MqlReadServiceResponse mqlResponse = new MqlReadServiceResponse();
            mqlResponse = mqlReadService.Read(query);
            List<dynamic> results = mqlResponse.Results;

            //Get the attribute key/value pairs
            for (int i = 0; i < results.Count; i++)
            {
                foreach (Attributes attribute in type.Attributes)
                {
                    if(attribute.resultType == "1")
                        identifiedAttributes.Add(attribute.Name, (string) results[i][attribute.FreebaseName]);

                    else if(attribute.resultType == "2")
                    {
                        var values = results[i][attribute.FreebaseName];
                        string refinedValues = "";
                        for (int j = 0; j < values.Count; j++)
                        {
                           refinedValues += values[j]["name"];
                           if (j != values.Count - 1)
                               refinedValues += ", ";
                        }
                        identifiedAttributes.Add(attribute.Name, refinedValues);
                    }
                }
            }
        }