Exemplo n.º 1
0
        public bool Read(string path, StudyUnitVM studyUnit)
        {
            Debug.Assert(!string.IsNullOrEmpty(path));
            StudyUnit studyUnitModel = studyUnit.StudyUnitModel;
            FileStream stream = File.OpenRead(path);
            SavFileParser parser = new SavFileParser(stream);
            List<Variable> variables = new List<Variable>();
            foreach (SpssLib.SpssDataset.Variable v in parser.Variables)
            {
                Variable variable = new Variable();
                variable.Title = v.Name;
                variable.Label = v.Label;
                variables.Add(variable);
                if (v.Type == SpssLib.SpssDataset.DataType.Text)
                {
                    variable.Response.TypeCode = Options.RESPONSE_TYPE_FREE_CODE;
                }
                else
                {
                    if (v.ValueLabels.Count > 0)
                    {
                        CategoryScheme categoryScheme = new CategoryScheme();
                        categoryScheme.Title = v.Label;
                        studyUnitModel.CategorySchemes.Add(categoryScheme);
                        CodeScheme codeScheme = new CodeScheme();
                        codeScheme.Title = v.Label; ;
                        studyUnitModel.CodeSchemes.Add(codeScheme);

                        variable.Response.TypeCode = Options.RESPONSE_TYPE_CHOICES_CODE;
                        variable.Response.CodeSchemeId = codeScheme.Id;
                        // 選択肢の作成
                        foreach (KeyValuePair<double, string> pair in v.ValueLabels)
                        {
                            Category category = new Category();
                            categoryScheme.Categories.Add(category);
                            category.Title = pair.Value;
                            category.CategorySchemeId = categoryScheme.Id;

                            Code code = new Code();
                            codeScheme.Codes.Add(code);
                            code.CategoryId = category.Id;
                            code.CodeSchemeId = codeScheme.Id;
                            code.Value = pair.Key.ToString();
                        }
                        // 欠損値の追加
                        if (v.MissingValues.Count > 0)
                        {
                            foreach (double missingValue in v.MissingValues)
                            {
                                string missingValueStr = missingValue.ToString();
                                if (ExistValue(codeScheme, missingValueStr))
                                {
                                    continue;
                                }
                                Category category = new Category();
                                categoryScheme.Categories.Add(category);
                                category.Title = Resources.MissingValue; //欠損値
                                category.IsMissingValue = true;
                                category.CategorySchemeId = categoryScheme.Id;

                                Code code = new Code();
                                codeScheme.Codes.Add(code);
                                code.CategoryId = category.Id;
                                code.CodeSchemeId = codeScheme.Id;
                                code.Value = missingValueStr;
                            }
                        }
                    }
                    else
                    {
                        variable.Response.TypeCode = Options.RESPONSE_TYPE_NUMBER_CODE;
                    }
                }
            }

            if (variables.Count > 0)
            {
                ConceptScheme conceptScheme = new ConceptScheme();
                conceptScheme.Title = EDOUtils.UniqueLabel(ConceptScheme.GetTitles(studyUnitModel.ConceptSchemes), Resources.ImportVariable); //インポートした変数
                string name = Path.GetFileName(path);
                conceptScheme.Memo = EDOUtils.UniqueLabel(ConceptScheme.GetMemos(studyUnitModel.ConceptSchemes), string.Format(Resources.ImportVariableFrom, name)); //{0}からインポートした変数

                Concept concept = new Concept();
                concept.Title = EDOUtils.UniqueLabel(ConceptScheme.GetConceptTitles(studyUnitModel.ConceptSchemes), Resources.ImportVariable);//インポートした変数
                concept.Content = EDOUtils.UniqueLabel(ConceptScheme.GetConceptContents(studyUnitModel.ConceptSchemes), string.Format(Resources.ImportVariableFrom, name));//{0}からインポートした変数
                conceptScheme.Concepts.Add(concept);
                studyUnitModel.ConceptSchemes.Add(conceptScheme);

                foreach (Variable variable in variables)
                {
                    Question question = new Question();
                    question.Title = variable.Label;
                    question.ConceptId = concept.Id;
                    question.Response.TypeCode = variable.Response.TypeCode;
                    question.Response.CodeSchemeId = variable.Response.CodeSchemeId;
                    studyUnitModel.Questions.Add(question);

                    variable.ConceptId = concept.Id;
                    variable.QuestionId = question.Id;
                    studyUnitModel.Variables.Add(variable);

                }
            }
            return true;
        }
Exemplo n.º 2
0
        public static ConceptScheme CreateConceptScheme(XElement conceptSchemeElem)
        {
            string id = (string)conceptSchemeElem.Attribute(ATTR_ID);
            if (id == null)
            {
                return null;
            }
            ConceptScheme conceptSchemeModel = new ConceptScheme();
            conceptSchemeModel.Id = id;
            conceptSchemeModel.Title = (string)conceptSchemeElem.Element(r + TAG_LABEL);
            conceptSchemeModel.Memo = (string)conceptSchemeElem.Element(r + TAG_DESCRIPTION);

            IEnumerable<XElement> elements = conceptSchemeElem.Descendants(c + TAG_CONCEPT);
            foreach (XElement conceptElem in elements)
            {
                string conceptId = (string)conceptElem.Attribute(ATTR_ID);
                if (conceptId == null)
                {
                    continue;
                }
                Concept conceptModel = new Concept();
                conceptModel.Id = conceptId;
                conceptModel.Title = (string)conceptElem.Element(r + TAG_LABEL);
                conceptModel.Content = (string)conceptElem.Element(r + TAG_DESCRIPTION);
                conceptSchemeModel.Concepts.Add(conceptModel);
            }
            return conceptSchemeModel;
        }
Exemplo n.º 3
0
 private Concept CloneConcept(Concept orgConcept)
 {
     Concept newConcept = (Concept)orgConcept.Clone();
     newConcept.Id = IDUtils.NewGuid();
     return newConcept;
 }
Exemplo n.º 4
0
 public bool Contains(string conceptId)
 {
     return(Concept.Find(Concepts, conceptId) != null);
 }
Exemplo n.º 5
0
 public static List <string> GetConceptContents(List <ConceptScheme> conceptSchemes)
 {
     return(Concept.GetContents(GetConcepts(conceptSchemes)));
 }
Exemplo n.º 6
0
 public ConceptVM(Concept concept)
 {
     this.concept = concept;
     this.books = new ObservableCollection<BookVM>();
 }
Exemplo n.º 7
0
 public void EndEdit()
 {
     if (!inEdit)
     {
         return;
     }
     inEdit = false;
     bakConcept = null;
     Memorize();
 }
Exemplo n.º 8
0
        public void BeginEdit()
        {
            if (inEdit)
            {
                return;
            }
            inEdit = true;

            bakConcept = concept.Clone() as Concept;
        }
Exemplo n.º 9
0
 private string JoinVariableIds(Concept concept)
 {
     List<Variable> variables = studyUnit.StudyUnitModel.FindVariablesByConceptId(concept.Id);
     IEnumerable<string> ids = Variable.GetIds(variables);
     IEnumerable<string> safeIds = ids.Select(p => ConvertId(p));
     return string.Join(" ", safeIds);
 }
Exemplo n.º 10
0
        private static void CreateConceptSchemes(XElement codebookElem, StudyUnit studyUnit, ReaderContext context)
        {
            XElement dataDscrElem = codebookElem.Element(cb + TAG_DATA_DSCR);
            if (dataDscrElem == null)
            {
                return;
            }

            Dictionary<string, List<string>> conceptIds = new Dictionary<string, List<string>>();

            List<ConceptScheme> allConceptSchemes = new List<ConceptScheme>();
            List<Concept> allConcepts = new List<Concept>();

            IEnumerable<XElement> varGrpElems = dataDscrElem.Elements(cb + TAG_VAR_GRP);
            foreach (XElement varGrpElem in varGrpElems)
            {
                string varGrpStr = (string)varGrpElem.Attribute(ATTR_VAR_GRP);
                if (!string.IsNullOrEmpty(varGrpStr))
                {
                    //大分類(ConceptScheme)
                    ConceptScheme conceptScheme = new ConceptScheme();
                    allConceptSchemes.Add(conceptScheme);

                    conceptScheme.Title = (string)varGrpElem.Element(cb + TAG_CONCEPT);
                    conceptScheme.Memo = (string)varGrpElem.Element(cb + TAG_DEFNTH);

                    List<string> ids = SplitIds(varGrpStr);
                    conceptIds[conceptScheme.Id] = ids;
                }
                else
                {
                    string id = (string)varGrpElem.Attribute(ATTR_ID);
                    if (!string.IsNullOrEmpty(id))
                    {
                        //イメージ(Concept)
                        Concept concept = new Concept();
                        concept.Id = id;
                        concept.Title = (string)varGrpElem.Element(cb + TAG_CONCEPT);
                        concept.Content = (string)varGrpElem.Element(cb + TAG_DEFNTH);
                        allConcepts.Add(concept);

                        string varStr = (string)varGrpElem.Attribute(ATTR_VAR);
                        List<string> ids = SplitIds(varStr);
                        context.VarIds[concept.Id] = ids; //コンセプトごとの変数IDを記憶(変数読み込み時に変数にconceptIdを設定するのに使う)
                    }
                }
            }

            foreach (ConceptScheme conceptScheme in allConceptSchemes)
            {
                List<string> ids = conceptIds[conceptScheme.Id];
                conceptScheme.Concepts = Concept.FindAll(allConcepts, ids);
            }

            if (allConceptSchemes.Count > 0)
            {
                studyUnit.ConceptSchemes = allConceptSchemes;
            }
        }