示例#1
0
        //--------------------------------------------------------------------------------
        //Methods
        //Constructor
        public FreebaseEntity(string id)
        {
            this.id = id;

            //initializing the services which will be used by this object
            this.textService = FreebaseServices.CreateTextService();
            this.imageService = FreebaseServices.CreateImageService();
            this.mqlReadService = FreebaseServices.CreateMqlReadService();

            unitOfWork = new UnitOfWork<DataContext>();
        }
示例#2
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);
                    }
                }
            }
        }