Пример #1
0
        }//不同的等级的关系虚拟表Dataset

        public static bool InsertRelationInfo(RelationData relation)
        {
            DataRow data  = relation.Tables[RelationData.RELATION_TABLE].Rows[0];
            bool    check = CheckDuplication(data);

            if (!check)
            {
                return(false);
            }
            string insertCommand = GetInsertCommand(relation);

            using (SQLiteConnection conn = new SQLiteConnection(globalParameters.dbPath))
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(insertCommand, conn))
                {
                    cmd.ExecuteNonQuery();
                }
                conn.Close();
            }
            if (relation.HasErrors)
            {
                relation.Tables[RelationData.RELATION_TABLE].GetErrors()[0].ClearErrors();
                return(false);
            }
            else
            {
                relation.AcceptChanges();
                return(true);
            }
        }
Пример #2
0
        private void AddMoneyToEndorcementReceiver(int endorcerId, int receiverId, RelationData relation, Guid transaction)
        {
            var addition = new ConfidenceValue(GetData(endorcerId).Trust, 1 - relation.Strength);
            var data     = RetrieveData(receiverId, transaction);

            data.AddMoney(addition, transaction);
        }
Пример #3
0
        protected override IList <RelationData> LoadRelationData(Query q)
        {
            if (!String.IsNullOrEmpty(ObjectRelationViewName))
            {
                var viewQuery = new Query(ObjectRelationViewName, q.Condition);
                var rels      = new List <RelationData>();
                DbMgr.Dalc.ExecuteReader(viewQuery, (rdr) => {
                    while (rdr.Read())
                    {
                        var rd       = new RelationData();
                        rd.SubjectId = Convert.ToInt64(rdr["subject_id"]);
                        rd.ObjectId  = Convert.ToInt64(rdr["object_id"]);
                        rd.PredicateClassCompactId = Convert.ToInt32(rdr["predicate_class_compact_id"]);

                        var subjectCompactClassId = rdr["subject_compact_class_id"];
                        if (subjectCompactClassId != null && !DBNull.Value.Equals(subjectCompactClassId))
                        {
                            rd.SubjectClassCompactId = Convert.ToInt32(subjectCompactClassId);
                        }

                        var objectCompactClassId = rdr["object_compact_class_id"];
                        if (objectCompactClassId != null && !DBNull.Value.Equals(objectCompactClassId))
                        {
                            rd.ObjectClassCompactId = Convert.ToInt32(objectCompactClassId);
                        }
                        rels.Add(rd);
                    }
                });
                return(rels);
            }
            else
            {
                return(base.LoadRelationData(q));
            }
        }
Пример #4
0
        public static bool UpdateRelationInfo(RelationData relation, string selectSource, string selectTarget)
        {
            string updateCommand = GetUpdateCommand(relation, selectSource, selectTarget);

            using (SQLiteConnection conn = new SQLiteConnection(globalParameters.dbPath))
            {
                conn.Open();
                string sq0 = "PRAGMA foreign_keys = 'on';";
                using (SQLiteCommand cmd = new SQLiteCommand(sq0, conn))
                {
                    cmd.ExecuteNonQuery();
                }
                using (SQLiteCommand cmd = new SQLiteCommand(updateCommand, conn))
                {
                    cmd.ExecuteNonQuery();
                }
                conn.Close();
            }
            if (relation.HasErrors)
            {
                relation.Tables[RelationData.RELATION_TABLE].GetErrors()[0].ClearErrors();
                return(false);
            }
            else
            {
                relation.AcceptChanges();
                return(true);
            }
        }
 private void GenerateRange(IEnumerable <RangeHPartitioningAttributeDefinition> attributePartitions, List <RangeHPartitionAttributeDefinition> partitionParts,
                            RelationData relation, ref VirtualHPartitioningDefinition result)
 {
     if (attributePartitions.Count() > 0)
     {
         var first = attributePartitions.First();
         foreach (var p in first.Partitions)
         {
             var pp = new List <RangeHPartitionAttributeDefinition>(partitionParts);
             pp.Add(p);
             GenerateRange(attributePartitions.Skip(1), pp, relation, ref result);
         }
     }
     else
     {
         var toPart = partitionParts.Take(partitionParts.Count - 1).Select(x => toSqlValueStringConverter.ConvertStringRepresentation(x.DbType, x.FromValueInclusive)).ToList();
         toPart.Add(partitionParts.Select(x => toSqlValueStringConverter.ConvertStringRepresentation(x.DbType, x.ToValueExclusive)).Last());
         result.PartitionStatements.Add(String.Format("PARTITION OF {0}.{1} FOR VALUES FROM ({2}) TO ({3})",
                                                      relation.SchemaName, relation.Name,
                                                      String.Join(",", partitionParts.Select(x => toSqlValueStringConverter.ConvertStringRepresentation(x.DbType, x.FromValueInclusive))),
                                                      String.Join(",", toPart)
                                                      )
                                        );
     }
 }
Пример #6
0
        public static List <relation> GetRelationArray(int level, string type) //得到不同level不同type的模块对应的关系数组
        {
            List <string>   modulesName   = ModulesOperator.ReadModulesForDiffLevelAndType(level, type);
            RelationData    relation      = RelationOperator.GetRelationInfoForDiffModList(modulesName);
            List <relation> relationArray = new List <relation>();

            for (int i = 0; i < relation.Tables[RelationData.RELATION_TABLE].Rows.Count; i++)
            {
                relation relationOne = new relation();
                relationOne.sourceName   = relation.Tables[RelationData.RELATION_TABLE].Rows[i][RelationData.SOURCENAME_FIELD].ToString();
                relationOne.targetName   = relation.Tables[RelationData.RELATION_TABLE].Rows[i][RelationData.TARGETNAME_FIELD].ToString();
                relationOne.bidirection  = relation.Tables[RelationData.RELATION_TABLE].Rows[i][RelationData.BIDIRECTION_FIELD].ToString();
                relationOne.relationName = relation.Tables[RelationData.RELATION_TABLE].Rows[i][RelationData.NAME_FIELD].ToString();
                relationOne.comment      = relation.Tables[RelationData.RELATION_TABLE].Rows[i][RelationData.COMMENT_FIELD].ToString();
                if (relation.Tables[RelationData.RELATION_TABLE].Rows[i][RelationData.SHOW_FIELD].ToString() == "1")
                {
                    relationOne.show = 1;
                }
                else
                {
                    relationOne.show = 0;
                }
                relationArray.Add(relationOne);
            }
            return(relationArray);
        }
Пример #7
0
 public static bool UpdateRelationCommentInfo(RelationData relation)
 {
     using (SQLiteConnection conn = new SQLiteConnection(globalParameters.dbPath))
     {
         conn.Open();
         for (int i = 0; i < relation.Tables[RelationData.RELATION_TABLE].Rows.Count; i++)
         {
             DataRow data          = relation.Tables[RelationData.RELATION_TABLE].Rows[i];
             string  updateCommand = GetUpdateCommentCommand(data);
             using (SQLiteCommand cmd = new SQLiteCommand(updateCommand, conn))
             {
                 cmd.ExecuteNonQuery();
             }
         }
         conn.Close();
     }
     if (relation.HasErrors)
     {
         relation.Tables[RelationData.RELATION_TABLE].GetErrors()[0].ClearErrors();
         return(false);
     }
     else
     {
         relation.AcceptChanges();
         return(true);
     }
 }
Пример #8
0
 public static bool ImportRelation(RelationData relation) //检查每一行是否有重复然后插入
 {
     for (int i = 0; i < relation.Tables[RelationData.RELATION_TABLE].Rows.Count; i++)
     {
         DataRow data  = relation.Tables[RelationData.RELATION_TABLE].Rows[i];
         bool    check = CheckDuplication(data);
         if (!check)
         {
             return(false);
         }
         string sourceName = "'" + relation.Tables[RelationData.RELATION_TABLE].Rows[i][RelationData.SOURCENAME_FIELD].ToString() + "'";
         string targetName = "'" + relation.Tables[RelationData.RELATION_TABLE].Rows[i][RelationData.TARGETNAME_FIELD].ToString() + "'";
         string sql1       = "insert into relation(sourceName,targetName,rname,bidirection,type,comment,show) select sourceName,targetName,rname,bidirection,type,comment,show from secondDb.relation where sourceName = " + sourceName + " and targetName = " + targetName;
         string sql00      = "ATTACH DATABASE '" + globalParameters.secondDbPath + "' as 'secondDb'";
         using (SQLiteConnection conn = new SQLiteConnection(globalParameters.dbPath))
         {
             conn.Open();
             using (SQLiteCommand cmd = new SQLiteCommand(sql00, conn))
             {
                 cmd.ExecuteNonQuery();
             }
             using (SQLiteCommand cmd = new SQLiteCommand(sql1, conn))
             {
                 cmd.ExecuteNonQuery();
             }
             conn.Close();
         }
     }
     return(true);
 }
Пример #9
0
        private void VersionInfoToData(VersionInfo vi, byte fileLocate)
        {
            VersionFile vf;

            for (int i = 0, count = vi.Files.Count; i < count; i++)
            {
                vf = vi.Files[i];
                RelationData rd = new RelationData();
                rd.index    = i;
                rd.origin   = vf.Origin;
                rd.guid     = vf.Guid;
                rd.encrypt  = vf.Encrypt;
                rd.size     = vf.Size;
                rd.fileType = vf.type;

                nameToRelation.Add(rd.origin, rd);

                versionFileData.fileLocate.Add(fileLocate);

                //childs
                for (int j = 0, jcount = vf.Childs.Count; j < jcount; j++)
                {
                    nameToRelation.Add(vf.Childs[j], rd);
                }
            }
        }
Пример #10
0
 public RelationInfo(ALine myAline)
 {
     InitializeComponent();
     this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
     relationName       = myAline.Text;
     relationdata       = RelationOperator.LoadRelationInfo();
     ShowInfo();
 }
        public RelationData GetReplacementOrOriginal(uint originalRelationId)
        {
            RelationData result = null;

            if (!evaluationReplacements.TryGetValue(originalRelationId, out result))
            {
                result = GetRelation(originalRelationId);
            }
            return(result);
        }
Пример #12
0
        private static string GetUpdateCommand(RelationData relation, string selectSource, string selectTarget)
        {
            DataRow data = relation.Tables[RelationData.RELATION_TABLE].Rows[0];
            string  cmdUpdate;
            string  change     = @"sourceName = '" + data[RelationData.SOURCENAME_FIELD] + "'," + "targetName = '" + data[RelationData.TARGETNAME_FIELD] + "'," + "rname = '" + data[RelationData.NAME_FIELD] + "'," + "type = '" + data[RelationData.TYPE_FIELD] + "'," + "bidirection = '" + data[RelationData.BIDIRECTION_FIELD] + "'," + "comment = '" + data[RelationData.COMMENT_FIELD] + "'," + "show ='" + data[RelationData.SHOW_FIELD] + "'";
            string  condition1 = @"sourceName = '" + selectSource + "'";
            string  condition2 = @"targetName = '" + selectTarget + "'";

            cmdUpdate = "UPDATE relation SET " + change + " WHERE " + condition1 + " and " + condition2;
            return(cmdUpdate);
        }
Пример #13
0
 //显示选中模块的关系
 private void btnSelected_Click(object sender, EventArgs e)
 {
     if (IsModuleChecked())
     {
         GetModulesList();
         relation = new RelationData();
         relation = RelationOperator.GetRelationInfoForImport(selectModule);
         dgv_importRelation.AutoGenerateColumns = false;
         dgv_importRelation.DataSource          = relation.Tables[RelationData.RELATION_TABLE].DefaultView;
     }
 }
Пример #14
0
        private static string GetInsertCommand(RelationData relation)
        {
            DataRow data = relation.Tables[RelationData.RELATION_TABLE].Rows[0];
            string  cmdInsert;
            string  name        = "'" + data[RelationData.NAME_FIELD] + "',";
            string  source      = "'" + data[RelationData.SOURCENAME_FIELD] + "',";
            string  target      = "'" + data[RelationData.TARGETNAME_FIELD] + "',";
            string  bidirection = "'" + data[RelationData.BIDIRECTION_FIELD] + "',";
            string  type        = "'" + data[RelationData.TYPE_FIELD] + "',";
            string  comment     = "'" + data[RelationData.COMMENT_FIELD] + "',";
            string  show        = "'" + data[RelationData.SHOW_FIELD] + "'";

            cmdInsert = "INSERT INTO relation(sourceName,targetName,rname,bidirection,type,comment,show) VALUES(" + source + target + name + bidirection + type + comment + show + ")";
            return(cmdInsert);
        }
Пример #15
0
        public static RelationData GetRelationInfoForImport(List <string> modulesName)
        {
            RelationData relationdata   = LoadRelationInfoForSecondDb();
            RelationData relationFilter = new RelationData();

            if (modulesName.Count > 0)
            {
                DataRow[] rowT3 = relationdata.Tables[RelationData.RELATION_TABLE].Select(RelationData.SOURCENAME_FIELD + " in " + GetString(modulesName) + " and " + RelationData.TARGETNAME_FIELD + " in " + GetString(modulesName));
                foreach (DataRow row in rowT3)
                {
                    relationFilter.Tables[RelationData.RELATION_TABLE].Rows.Add(row.ItemArray);
                }
            }
            return(relationFilter);
        }
Пример #16
0
        private void RemoveRelations(string name, params string[] objectIds)
        {
            RelationSetData relationSetData = this.CreateRelationSetData(name);

            if (objectIds != null)
            {
                foreach (string text in objectIds)
                {
                    Relation     value        = new Relation(SharePointNotification.RelationTypeIds[name], new Guid(text));
                    RelationData relationData = new RelationData();
                    relationData.Value = this.SerializeObjectXML <Relation>(value);
                    relationSetData.RemovedRelations[text] = relationData;
                }
            }
            this.directoryObjectData.RelationSets[name] = relationSetData;
        }
Пример #17
0
        public static RelationData LoadRelationInfo()
        {
            RelationData data = new RelationData();
            string       sql0 = "select * from relation";

            using (SQLiteConnection conn = new SQLiteConnection(globalParameters.dbPath))
            {
                conn.Open();
                using (SQLiteDataAdapter command = new SQLiteDataAdapter(sql0, conn))
                {
                    command.Fill(data.Tables[RelationData.RELATION_TABLE]);
                    conn.Close();
                    return(data);
                }
            }
        }
Пример #18
0
        public static List <ModulesList> CountModuleLevelAndType(int level, string type)
        {
            List <string>      modulesName = ReadModulesForDiffLevelAndType(level, type);
            RelationData       relation    = RelationOperator.GetRelationInfoForDiffModList(modulesName);//Type为3
            List <ModulesList> modules     = new List <ModulesList>();

            for (int i = 0; i < modulesName.Count; i++)
            {
                ModulesList module = new ModulesList();
                DataRow[]   rl     = relation.Tables[RelationData.RELATION_TABLE].Select(RelationData.SOURCENAME_FIELD + " = '" + modulesName[i] + "' or " + RelationData.TARGETNAME_FIELD + "='" + modulesName[i] + "'");
                module.name  = modulesName[i];
                module.count = rl.Length;
                modules.Add(module);
            }
            return(modules);
        }
        private IndexDefinitionPermutations GenerateAllPermutations(RelationData relation, ISet <AttributeData> attributes)
        {
            var result = new IndexDefinitionPermutations();

            for (int i = 1; i <= attributes.Count; i++)
            {
                result.PermutationsByGeneration.Add(i, new HashSet <IndexDefinition>());
                var permutations = PermuteUtils.Permute(attributes, i);
                foreach (var p in permutations)
                {
                    var indexToAdd = new IndexDefinition(IndexStructureType.BTree, relation, p, null);
                    result.PermutationsByGeneration[i].Add(indexToAdd);
                }
            }
            return(result);
        }
 private RelationData GetRelation(uint relationId)
 {
     if (!allRelations.ContainsKey(relationId))
     {
         using (var scope = new DatabaseScope(databaseName))
         {
             var          loadedRelation = relationsRepository.Get(relationId);
             RelationData relationData   = null;
             if (loadedRelation != null)
             {
                 relationData = new RelationData(loadedRelation);
             }
             allRelations.Add(relationId, relationData);
         }
     }
     return(allRelations[relationId]);
 }
Пример #21
0
        private void RelationEditForm_Load(object sender, EventArgs e)
        {
            dataGridView_relation.AutoGenerateColumns = false;
            relationdata = RelationOperator.LoadRelationInfo();
            dataGridView_relation.DataSource = relationdata.Tables[RelationData.RELATION_TABLE].DefaultView;

            dgv_source.AutoGenerateColumns = false;
            moduledata            = ModulesOperator.LoadModulesInfo();
            dgv_source.DataSource = moduledata.Tables[ModuleData.MODULES_TABLE].DefaultView;

            dgv_target.AutoGenerateColumns = false;
            moduledata            = ModulesOperator.LoadModulesInfo();
            dgv_target.DataSource = moduledata.Tables[ModuleData.MODULES_TABLE].DefaultView;

            pageStatus = RecordStatus.View;
            SetFormControlerStatus();
            SetFormControlerData();
        }
 protected override void OnExecute()
 {
     using (var scope = new DatabaseScope(context.Database.Name))
     {
         var existingIndices = indicesRepository.GetAll();
         foreach (var i in existingIndices)
         {
             var relation           = relationsRepository.Get(i.RelationID);
             var relationData       = new RelationData(relation);
             var attributes         = new List <AttributeData>();
             var includedAttributes = new List <AttributeData>();
             foreach (var atrributeName in i.AttributesNames)
             {
                 var attribute = attributesRepository.Get(relation.ID, atrributeName);
                 var toAdd     = new AttributeData(relationData, attribute);
                 if (IsIncludedAttribute(i.CreateDefinition, attribute.Name))
                 {
                     includedAttributes.Add(toAdd);
                 }
                 else
                 {
                     attributes.Add(toAdd);
                 }
             }
             var existingIndexToAdd = new IndexDefinition(Convert(i.AccessMethod), relationData, attributes, includedAttributes);
             if (context.StatementsData.AllQueriesByRelation.TryGetValue(relation.ID, out var possibleQueriesForIndex))
             {
                 foreach (var statementQueryPair in possibleQueriesForIndex)
                 {
                     var normalizedStatementID = statementQueryPair.NormalizedStatementID;
                     var normalizedStatement   = context.StatementsData.All[normalizedStatementID].NormalizedStatement;
                     var query         = statementQueryPair.Query;
                     var extractedData = context.StatementsExtractedData.DataPerQuery[statementQueryPair];
                     if (IndexApplicability.IsIndexApplicableForQuery(extractedData, existingIndexToAdd))
                     {
                         context.IndicesDesignData.ExistingIndices.TryAddPossibleIndices(new[] { existingIndexToAdd }, normalizedStatement, query);
                     }
                 }
             }
         }
     }
 }
Пример #23
0
    protected virtual void LoadData()
    {
        training_file = Path.Combine(data_dir, training_file);
        if (test_file != null)
        {
            test_file = Path.Combine(data_dir, test_file);
        }

        // user attributes
        if (user_attributes_file != null)
        {
            user_attributes = AttributeData.Read(Path.Combine(data_dir, user_attributes_file), user_mapping);
        }
        if (recommender is IUserAttributeAwareRecommender)
        {
            ((IUserAttributeAwareRecommender)recommender).UserAttributes = user_attributes;
        }

        // item attributes
        if (item_attributes_file != null)
        {
            item_attributes = AttributeData.Read(Path.Combine(data_dir, item_attributes_file), item_mapping);
        }
        if (recommender is IItemAttributeAwareRecommender)
        {
            ((IItemAttributeAwareRecommender)recommender).ItemAttributes = item_attributes;
        }

        // user relation
        if (recommender is IUserRelationAwareRecommender)
        {
            ((IUserRelationAwareRecommender)recommender).UserRelation = RelationData.Read(Path.Combine(data_dir, user_relations_file), user_mapping);
            Console.WriteLine("relation over {0} users", ((IUserRelationAwareRecommender)recommender).NumUsers);
        }

        // item relation
        if (recommender is IItemRelationAwareRecommender)
        {
            ((IItemRelationAwareRecommender)recommender).ItemRelation = RelationData.Read(Path.Combine(data_dir, item_relations_file), item_mapping);
            Console.WriteLine("relation over {0} items", ((IItemRelationAwareRecommender)recommender).NumItems);
        }
    }
Пример #24
0
        //导入
        private void btn_SelectFinish_Click(object sender, EventArgs e)
        {
            selectRelation = new RelationData();
            string source;
            string target;

            for (int i = 0; i <= this.dgv_importRelation.RowCount - 1; i++)
            {
                if (dgv_importRelation.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
                {
                    source = dgv_importRelation.Rows[i].Cells[2].Value.ToString();
                    target = dgv_importRelation.Rows[i].Cells[3].Value.ToString();
                    DataRow odr = relation.Tables[RelationData.RELATION_TABLE].Select(RelationData.SOURCENAME_FIELD + "='" + source + "' and  " + RelationData.TARGETNAME_FIELD + "='" + target + "'")[0];
                    DataRow dr  = selectRelation.Tables[RelationData.RELATION_TABLE].NewRow();
                    dr[2] = odr[RelationData.NAME_FIELD];
                    dr[0] = odr[RelationData.SOURCENAME_FIELD];
                    dr[1] = odr[RelationData.TARGETNAME_FIELD];
                    dr[3] = odr[RelationData.BIDIRECTION_FIELD].ToString();
                    dr[4] = odr[RelationData.TYPE_FIELD].ToString();
                    dr[5] = odr[RelationData.COMMENT_FIELD].ToString();
                    dr[6] = odr[RelationData.SHOW_FIELD];
                    selectRelation.Tables[RelationData.RELATION_TABLE].Rows.Add(dr);
                }
            }
            if (IsModuleChecked())
            {
                GetModulesList();
                if (ModulesOperator.importModules(selectModule))
                {
                    MessageBox.Show(" 信息系统导入成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            if (IsRelationChecked())
            {
                if (RelationOperator.ImportRelation(selectRelation))
                {
                    MessageBox.Show(" 关系导入成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                MainForm.isSaved = false;
            }
        }
Пример #25
0
        public static RelationData LoadRelationInfoForSecondDb()
        {
            RelationData data  = new RelationData();
            string       sql0  = "select * from secondDb.relation";
            string       sql00 = "ATTACH DATABASE '" + globalParameters.secondDbPath + "' as 'secondDb'";

            using (SQLiteConnection conn = new SQLiteConnection(globalParameters.dbPath))
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(sql00, conn))
                {
                    cmd.ExecuteNonQuery();
                }
                using (SQLiteDataAdapter command = new SQLiteDataAdapter(sql0, conn))
                {
                    command.Fill(data.Tables[RelationData.RELATION_TABLE]);
                    conn.Close();
                    return(data);
                }
            }
        }
Пример #26
0
        //将数据存储为二进制
        public void SaveDependsDataFile(string savePath = null)
        {
            savePath = string.IsNullOrEmpty(savePath) ? CACHE_PATH : savePath;
            FileStream   fileStream   = new FileStream(savePath, FileMode.Create, FileAccess.Write);
            StreamWriter streamWriter = new StreamWriter(fileStream);

            //转换
            FileData fileData = new FileData();

            fileData.version    = VERSION;
            fileData.date       = XTimeTools.NowTimeStampMs;
            fileData.assetPaths = _strList.ToArray();

            var assetDependList = new List <RelationData>();

            foreach (var depData in _data.Values)
            {
                var relationData = new RelationData();
                relationData.index = depData.assetPathIndex;
                relationData.hash  = depData.assetDependencyHash;

                relationData.dependsPathIndex = depData.dependsPathIndex.ToArray();

                assetDependList.Add(relationData);
            }
            fileData.assetDepends     = assetDependList.ToArray();
            fileData.assetCount       = _strList.Count;
            fileData.assetDependCount = assetDependList.Count;

            /////

            StringBuilder indeBuilder = new StringBuilder();

            streamWriter.WriteLine(string.Format("{0},{1}", fileData.version, fileData.date));
            streamWriter.WriteLine(string.Format("{0},{1}", fileData.assetCount, fileData.assetDependCount));

            for (int i = 0; i < fileData.assetCount; i++)
            {
                streamWriter.WriteLine(string.Format("{0}={1}", i, fileData.assetPaths[i]));
            }

            for (int i = 0; i < fileData.assetDependCount; i++)
            {
                var assetDepend = fileData.assetDepends[i];
                indeBuilder.Clear();
                for (int j = 0; j < assetDepend.dependsPathIndex.Length; j++)
                {
                    indeBuilder.Append(assetDepend.dependsPathIndex[j]);
                    if (j < assetDepend.dependsPathIndex.Length - 1)
                    {
                        indeBuilder.Append(",");
                    }
                }
                var depStr = indeBuilder.ToString();

                streamWriter.WriteLine(string.Format("{0}({1}):{2}", assetDepend.index, assetDepend.hash, depStr));
            }

            streamWriter.Close();
            fileStream.Close();

            streamWriter.Dispose();
            fileStream.Dispose();

            IsSaved = true;
        }
 private AttributeData CreateIndexAttribute(RelationData relationData, IRelationAttribute attribute)
 {
     return(new AttributeData(relationData, attribute));
 }
Пример #28
0
    static void LoadData(string data_dir,
                         string user_attributes_file, string item_attributes_file,
                         string user_relation_file, string item_relation_file,
                         bool static_data)
    {
        if (training_file == null)
        {
            Usage("Program expects --training-file=FILE.");
        }

        TimeSpan loading_time = Utils.MeasureTime(delegate() {
            // read training data
            if (file_format == RatingFileFormat.DEFAULT)
            {
                training_data = static_data ? RatingPredictionStatic.Read(Path.Combine(data_dir, training_file), user_mapping, item_mapping, rating_type)
                                                                : MyMediaLite.IO.RatingPrediction.Read(Path.Combine(data_dir, training_file), user_mapping, item_mapping);
            }
            else if (file_format == RatingFileFormat.MOVIELENS_1M)
            {
                training_data = MovieLensRatingData.Read(Path.Combine(data_dir, training_file), user_mapping, item_mapping);
            }
            else if (file_format == RatingFileFormat.KDDCUP_2011)
            {
                training_data = MyMediaLite.IO.KDDCup2011.Ratings.Read(Path.Combine(data_dir, training_file));
            }

            recommender.Ratings = training_data;

            // user attributes
            if (recommender is IUserAttributeAwareRecommender)             // TODO also support the MovieLens format here
            {
                if (user_attributes_file == string.Empty)
                {
                    Usage("Recommender expects --user-attributes=FILE.");
                }
                else
                {
                    ((IUserAttributeAwareRecommender)recommender).UserAttributes = AttributeData.Read(Path.Combine(data_dir, user_attributes_file), user_mapping);
                }
            }

            // item attributes
            if (recommender is IItemAttributeAwareRecommender)
            {
                if (item_attributes_file == string.Empty)
                {
                    Usage("Recommender expects --item-attributes=FILE.");
                }
                else
                {
                    ((IItemAttributeAwareRecommender)recommender).ItemAttributes = AttributeData.Read(Path.Combine(data_dir, item_attributes_file), item_mapping);
                }
            }

            // user relation
            if (recommender is IUserRelationAwareRecommender)
            {
                if (user_relation_file == string.Empty)
                {
                    Usage("Recommender expects --user-relations=FILE.");
                }
                else
                {
                    ((IUserRelationAwareRecommender)recommender).UserRelation = RelationData.Read(Path.Combine(data_dir, user_relation_file), user_mapping);
                    Console.WriteLine("relation over {0} users", ((IUserRelationAwareRecommender)recommender).NumUsers);
                }
            }

            // item relation
            if (recommender is IItemRelationAwareRecommender)
            {
                if (user_relation_file == string.Empty)
                {
                    Usage("Recommender expects --item-relations=FILE.");
                }
                else
                {
                    ((IItemRelationAwareRecommender)recommender).ItemRelation = RelationData.Read(Path.Combine(data_dir, item_relation_file), item_mapping);
                    Console.WriteLine("relation over {0} items", ((IItemRelationAwareRecommender)recommender).NumItems);
                }
            }

            // read test data
            if (test_file != null)
            {
                if (file_format == RatingFileFormat.MOVIELENS_1M)
                {
                    test_data = MovieLensRatingData.Read(Path.Combine(data_dir, test_file), user_mapping, item_mapping);
                }
                else
                {
                    test_data = RatingPredictionStatic.Read(Path.Combine(data_dir, test_file), user_mapping, item_mapping, rating_type);
                }
                // TODO add KDD Cup
            }
        });

        Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "loading_time {0,0:0.##}", loading_time.TotalSeconds));
    }
Пример #29
0
    static void LoadData()
    {
        TimeSpan loading_time = Utils.MeasureTime(delegate() {
            // training data
            training_data = ItemRecommendation.Read(Path.Combine(data_dir, training_file), user_mapping, item_mapping);

            // relevant users and items
            if (relevant_users_file != null)
            {
                relevant_users = new HashSet <int>(user_mapping.ToInternalID(Utils.ReadIntegers(Path.Combine(data_dir, relevant_users_file))));
            }
            else
            {
                relevant_users = training_data.AllUsers;
            }
            if (relevant_items_file != null)
            {
                relevant_items = new HashSet <int>(item_mapping.ToInternalID(Utils.ReadIntegers(Path.Combine(data_dir, relevant_items_file))));
            }
            else
            {
                relevant_items = training_data.AllItems;
            }

            if (!(recommender is MyMediaLite.ItemRecommendation.Random))
            {
                ((ItemRecommender)recommender).Feedback = training_data;
            }

            // user attributes
            if (recommender is IUserAttributeAwareRecommender)
            {
                if (user_attributes_file == null)
                {
                    Usage("Recommender expects --user-attributes=FILE.");
                }
                else
                {
                    ((IUserAttributeAwareRecommender)recommender).UserAttributes = AttributeData.Read(Path.Combine(data_dir, user_attributes_file), user_mapping);
                }
            }

            // item attributes
            if (recommender is IItemAttributeAwareRecommender)
            {
                if (item_attributes_file == null)
                {
                    Usage("Recommender expects --item-attributes=FILE.");
                }
                else
                {
                    ((IItemAttributeAwareRecommender)recommender).ItemAttributes = AttributeData.Read(Path.Combine(data_dir, item_attributes_file), item_mapping);
                }
            }
            if (filtered_eval)
            {
                if (item_attributes_file == null)
                {
                    Usage("--filtered-evaluation expects --item-attributes=FILE.");
                }
                else
                {
                    item_attributes = AttributeData.Read(Path.Combine(data_dir, item_attributes_file), item_mapping);
                }
            }

            // user relation
            if (recommender is IUserRelationAwareRecommender)
            {
                if (user_relations_file == null)
                {
                    Usage("Recommender expects --user-relation=FILE.");
                }
                else
                {
                    ((IUserRelationAwareRecommender)recommender).UserRelation = RelationData.Read(Path.Combine(data_dir, user_relations_file), user_mapping);
                    Console.WriteLine("relation over {0} users", ((IUserRelationAwareRecommender)recommender).NumUsers);                     // TODO move to DisplayDataStats
                }
            }

            // item relation
            if (recommender is IItemRelationAwareRecommender)
            {
                if (user_relations_file == null)
                {
                    Usage("Recommender expects --item-relation=FILE.");
                }
                else
                {
                    ((IItemRelationAwareRecommender)recommender).ItemRelation = RelationData.Read(Path.Combine(data_dir, item_relations_file), item_mapping);
                    Console.WriteLine("relation over {0} items", ((IItemRelationAwareRecommender)recommender).NumItems);                     // TODO move to DisplayDataStats
                }
            }

            // test data
            if (test_ratio == 0)
            {
                if (test_file != null)
                {
                    test_data = ItemRecommendation.Read(Path.Combine(data_dir, test_file), user_mapping, item_mapping);
                }
            }
            else
            {
                var split     = new PosOnlyFeedbackSimpleSplit <PosOnlyFeedback <SparseBooleanMatrix> >(training_data, test_ratio);
                training_data = split.Train[0];
                test_data     = split.Test[0];
            }
        });

        Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "loading_time {0,0:0.##}", loading_time.TotalSeconds));
    }
    protected virtual void LoadData()
    {
        training_file = Path.Combine(data_dir, training_file);
        if (test_file != null)
        {
            test_file = Path.Combine(data_dir, test_file);
        }

        // user attributes
        if (user_attributes_file != null)
        {
            string[] files = user_attributes_file.Split(' ');
            foreach (string file in files)
            {
                if (file.Length > 0)
                {
                    user_attributes.Add(AttributeData.Read(Path.Combine(data_dir, file), user_mapping));
                }
            }
        }



        //Original

        for (int i = 0; i < recommenders.Count; i++)
        {
            if (recommenders[i] is IUserAttributeAwareRecommender)
            {
                ((IUserAttributeAwareRecommender)recommenders[i]).UserAttributes = user_attributes[0];
                if (user_attributes.Count > 1)
                {
                    ((IUserAttributeAwareRecommender)recommenders[i]).AdditionalUserAttributes = user_attributes.GetRange(1, user_attributes.Count - 1);
                }
                else
                {
                    ((IUserAttributeAwareRecommender)recommenders[i]).AdditionalUserAttributes = new List <IBooleanMatrix>();
                }
            }
        }

        // item attributes
        item_attributes = new List <IBooleanMatrix>();
        if (item_attributes_file != null)
        {
            string[] files = item_attributes_file.Split(' ');
            foreach (string file in files)
            {
                if (file.Length > 0)
                {
                    item_attributes.Add(AttributeData.Read(Path.Combine(data_dir, file), item_mapping));
                }
            }
        }


        //Cada um pega um metadado
        for (int i = 0; i < item_attributes.Count; i++)
        {
            if (recommenders[i] is IItemAttributeAwareRecommender)
            {
                ((IItemAttributeAwareRecommender)recommenders[i]).ItemAttributes           = item_attributes[i];
                ((IItemAttributeAwareRecommender)recommenders[i]).AdditionalItemAttributes = new List <IBooleanMatrix>();
            }
        }


        //Original

        /*
         * for (int i = 0; i < recommenders.Count; i++)
         * {
         *  if (recommenders[i] is IItemAttributeAwareRecommender)
         *  {
         *      ((IItemAttributeAwareRecommender)recommenders[i]).ItemAttributes = item_attributes[0];
         *      if (item_attributes.Count > 1)
         *          ((IItemAttributeAwareRecommender)recommenders[i]).AdditionalItemAttributes = item_attributes.GetRange(1, item_attributes.Count - 1);
         *      else
         *          ((IItemAttributeAwareRecommender)recommenders[i]).AdditionalItemAttributes = new List<IBooleanMatrix>();
         *  }
         *
         * }
         *
         */



        for (int i = 0; i < recommenders.Count; i++)
        {
            // user relation
            if (recommenders[i] is IUserRelationAwareRecommender)
            {
                ((IUserRelationAwareRecommender)recommenders[i]).UserRelation = RelationData.Read(Path.Combine(data_dir, user_relations_file), user_mapping);
                Console.WriteLine("relation over {0} users", ((IUserRelationAwareRecommender)recommenders[i]).NumUsers);
            }

            // item relation
            if (recommenders[i] is IItemRelationAwareRecommender)
            {
                ((IItemRelationAwareRecommender)recommenders[i]).ItemRelation = RelationData.Read(Path.Combine(data_dir, item_relations_file), item_mapping);
                Console.WriteLine("relation over {0} items", ((IItemRelationAwareRecommender)recommenders[i]).NumItems);
            }
        }
    }