Exemple #1
0
        internal override bool ExecuteB(JsonObject json, JsonObject parent)
        {
            JsonValue old = WokeJ.GetElementByKey(json, Key);

            if (old == null)
            {
                return(false);
            }
            if (old is JsonPrimitive oldP)
            {
                json[Key] = ExecuteE(oldP, json, parent);
                return(old != json[Key]);
            }
            else if (old is JsonArray oldA)
            {
                // TODO
                return(false);
                //WokeJ.ForAllElements(oldA, e => ExecuteB(e, parent));
                //return true; // overapproximation
            }
            else
            if (Config.Debug)
            {
                Console.WriteLine($"[ERROR] Cannot truncate a dictionary, skipped");
            }
            return(false);
        }
Exemple #2
0
        internal override bool ExecuteB(JsonObject json, JsonObject parent)
        {
            JsonValue old = WokeJ.GetElementByKey(json, Key);

            if (old == null)
            {
                return(false);
            }
            if (old is JsonPrimitive oldP)
            {
                json[Key] = ExecuteE(oldP, json, parent);
                return(old != json[Key]);
            }
            else if (old is JsonArray oldA)
            {
                Console.WriteLine($"got to the array {oldA}");
                WokeJ.MapReduce(oldA, e => e is JsonPrimitive ep ? ExecuteE(ep, json, parent) : e);
                return(true); // overapproximation
            }
            else
            if (Config.Debug)
            {
                Console.WriteLine($"[ERROR] Cannot truncate a dictionary, skipped");
            }
            return(false);
        }
Exemple #3
0
        internal override bool ExecuteB(JsonObject json, JsonObject parent)
        {
            JsonValue old = WokeJ.GetElementByKey(json, Key);

            if (old == null)
            {
                return(false);
            }
            json.Remove(Key);
            return(true);
        }
Exemple #4
0
 internal override JsonPrimitive ExecuteE(JsonPrimitive jp, JsonValue json, JsonValue parent)
 {
     if (Value[0] == '$')
     {
         return(new JsonPrimitive(IO.BareValue(WokeJ.GetElementByKey(json, Value.Substring(1)))));
     }
     else
     {
         return(new JsonPrimitive(Value));
     }
 }
Exemple #5
0
        internal override bool ExecuteB(JsonObject json, JsonObject parent)
        {
            JsonValue old = WokeJ.GetElementByKey(json, Key);

            if (Value[0] == '$')
            {
                return(_assign(old, json, parent, Key, IO.BareValue(WokeJ.GetElementByKey(json, Value.Substring(1)))));
            }
            else
            {
                return(_assign(old, json, parent, Key, Value));
            }
        }
Exemple #6
0
 internal override JsonPrimitive ExecuteE(JsonPrimitive jp, JsonValue json, JsonValue parent)
 {
     if (json == null)
     {
         if (Config.Debug)
         {
             Console.WriteLine("[ERROR] Cannot rename something outside a dictionary");
         }
         return(jp);
     }
     WokeJ.AddKeyValue(json, KeyNew, jp);
     return(null);
 }
Exemple #7
0
        internal override bool ExecuteB(JsonObject json, JsonObject parent)
        {
            JsonValue old = WokeJ.GetElementByKey(json, Key);
            JsonValue neu = WokeJ.GetElementByKey(parent, ParentKey);

            if (neu != null)
            {
                WokeJ.AddKeyValue(json, Key, neu);
                return(WokeJ.GetElementByKey(json, Key) != old);
            }
            else
            {
                return(false);
            }
        }
Exemple #8
0
        internal override bool ExecuteB(JsonObject json, JsonObject parent)
        {
            if (json == null)
            {
                if (Config.Debug)
                {
                    Console.WriteLine("[ERROR] Cannot rename something outside a dictionary");
                }
                return(false);
            }
            var old = WokeJ.GetElementByKey(json, KeyOld);

            if (old == null)
            {
                return(false);
            }
            WokeJ.AddKeyValue(json, KeyNew, old);
            json.Remove(KeyOld);
            return(true); // overapptoximation
        }
Exemple #9
0
 private void EnforceInLeaves(DirectoryInfo corpus)
 {
     foreach (var unoF in corpus.GetDirectories("*"))
     {
         foreach (var duoF in unoF.GetDirectories("*"))
         {
             Dictionary <string, JsonObject> PossibleParents = new Dictionary <string, JsonObject>();
             foreach (var treJ in duoF.GetFiles("*.json"))
             {
                 var  json    = WokeJ.ParseJson(treJ.FullName) as JsonObject;
                 bool changed = false;
                 foreach (var rule in Rules[PathToConf])
                 {
                     changed |= rule.Enforce(json, null); // TODO: parents of conferences
                 }
                 if (changed)
                 {
                     File.WriteAllText(treJ.FullName, WokeJ.UnParseJson(json));
                     //Console.WriteLine(XBibParser.UnParseJson(json));
                     //throw new Exception();
                     Console.WriteLine($"Updated {unoF}/{duoF}/{treJ}");
                 }
                 PossibleParents[Path.GetFileNameWithoutExtension(treJ.Name)] = json;
             }
             foreach (var treF in duoF.GetDirectories("*"))
             {
                 int        i = 0, j = 0;
                 JsonObject Parent = null;
                 if (PossibleParents.ContainsKey(treF.Name))
                 {
                     Parent = PossibleParents[treF.Name];
                 }
                 foreach (var quaJ in treF.GetFiles("*.json"))
                 {
                     JsonObject json = WokeJ.ParseJson(quaJ.FullName) as JsonObject;
                     if (json == null)
                     {
                         continue;
                     }
                     bool changed = false;
                     foreach (var rule in Rules[PathToPaper])
                     {
                         changed |= rule.Enforce(json, Parent);
                     }
                     if (changed)
                     {
                         //Console.WriteLine("qapla!");
                         File.WriteAllText(quaJ.FullName, WokeJ.UnParseJson(json));
                         //Console.WriteLine(XBibParser.UnParseJson(json));
                         //throw new Exception();
                         j++;
                     }
                     i++;
                 }
                 if (j > 0)
                 {
                     Console.WriteLine($"{unoF.Name}/{duoF.Name}/{treF.Name}: {i} entries{(Parent == null ? "" : " + parent")} = {j} updated");
                 }
             }
         }
     }
 }