bool ObjectLoaded(string text) { bool r = false; try { r = ((VoxML.LoadFromText(text)).Lex.Pred == loadedObject.Lex.Pred); } catch (FileNotFoundException ex) { } return(r); }
VoxML LoadMarkup(string text) { VoxML voxml = new VoxML(); try { voxml = VoxML.LoadFromText(text); AssignVoxMLValues(voxml); } catch (FileNotFoundException ex) { } return(voxml); }
public void AddNewRelation(List <GameObject> objs, string relation, bool recurse = true) { VoxML voxml = null; try { using (StreamReader sr = new StreamReader( string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("relations/{0}.xml", relation)))) { voxml = VoxML.LoadFromText(sr.ReadToEnd()); } } catch (Exception e) { Debug.Log(e.Message); } foreach (List <GameObject> key in relations.Keys) { if (key.SequenceEqual(objs)) { if (!relations[key].ToString().Contains(relation)) { Debug.Log(string.Format("Adding {0} {1} {2}", relation, objs[0], objs[1])); relations[key] += string.Format(",{0}", relation); if (recurse) { if ((voxml != null) && (voxml.Type.Corresps.Where(c => c.Value == "reflexive").ToList().Count > 0)) { AddNewRelation(Enumerable.Reverse(objs).ToList(), relation, false); } } } UpdateRelationStrings(); return; } } foreach (List <GameObject> key in relations.Keys) { if (key.SequenceEqual(objs.Reverse <GameObject>().ToList())) { if (relations[key].ToString().Contains(relation)) { return; } } } try { Debug.Log(string.Format("Adding {0} {1} {2}", relation, objs[0], objs[1])); } catch (Exception e) { } relations.Add(objs, relation); // add key-val pair or modify value if key already exists if (recurse) { if ((voxml != null) && (voxml.Type.Corresps.Where(c => c.Value == "reflexive").ToList().Count > 0)) { AddNewRelation(Enumerable.Reverse(objs).ToList(), relation, false); } } UpdateRelationStrings(); }
public void RemoveRelation(List <GameObject> objs, string relation, bool recurse = true) { VoxML voxml = null; try { using (StreamReader sr = new StreamReader( string.Format("{0}/{1}", Data.voxmlDataPath, string.Format("relations/{0}.xml", relation)))) { voxml = VoxML.LoadFromText(sr.ReadToEnd()); } } catch (Exception e) { // TODO: fix //Debug.Log (e.Message); } foreach (List <GameObject> key in relations.Keys) { if (key.SequenceEqual(objs)) { if (relations[key].ToString().Contains(relation)) { Debug.Log(string.Format("Removing {0} {1} {2}", relation, objs[0], objs[1])); if (relations[key].ToString().Contains(",")) { Debug.Log(relations[key]); relations[key] = Regex.Replace(relations[key].ToString(), string.Format("{0},?", relation), ""); if (relations[key].ToString().EndsWith(",")) { relations[key] = relations[key].ToString().Trim(new char[] { ',' }); } Debug.Log(relations[key]); if (recurse) { if ((voxml != null) && (voxml.Type.Corresps.Where(c => c.Value == "reflexive").ToList().Count > 0)) { RemoveRelation(Enumerable.Reverse(objs).ToList(), relation, false); } } UpdateRelationStrings(); return; } else { relations.Remove(key); if (recurse) { if ((voxml != null) && (voxml.Type.Corresps.Where(c => c.Value == "reflexive").ToList().Count > 0)) { RemoveRelation(Enumerable.Reverse(objs).ToList(), relation, false); } } UpdateRelationStrings(); return; } } } } }