def _parse_source(self, source_path):
     result = read_json_object(path=source_path)
     i = 1
     for an_elem in result:
         an_elem[KEY_RANKING_WITHIN_SOURCE] = i
         i += 1
     return result
 def exec_command(self, string_return=False):
     target_classes = read_json_object(self._in_file)
     self._count_instances(target_classes)
     self._erase_instance_lists(target_classes)
     self._add_current_rank(target_classes, KEY_POS_CLASSRANK)
     self._sort_by_instances(target_classes)
     self._add_current_rank(target_classes, KEY_POS_INSTANCE_COUNTING)
     self._serialize_results(target_classes, string_return)
 def exec_command(self, string_return=False):
     target_classes = read_json_object(self._in_file)
     self._count_instances(target_classes)
     self._erase_instance_lists(target_classes)
     self._add_current_rank(target_classes, KEY_POS_CLASSRANK)
     self._sort_by_instances(target_classes)
     self._add_current_rank(target_classes, KEY_POS_INSTANCE_COUNTING)
     self._serialize_results(target_classes, string_return)
 def _read_raw_classes(self):
     # return [{"id": "Q31",
     #          KEY_ACCUMULATED: 8,
     #          KEY_INSTANCES: {"P1" : ["Q5", "Q3"] # 2 instances
     #                          }
     #          },
     #         {"id": "Q35",
     #          KEY_ACCUMULATED: 8,
     #          KEY_INSTANCES:{"P1" : ["Q5", "Q3"],
     #                         "P2" : ["Q3", "Q2", "Q1"]  # 4 instances (Q3 repeated)
     #                          }}]
     return read_json_object(self._in_ag_scores)
 def _read_raw_classes(self):
     # return [{"id": "Q31",
     #          KEY_ACCUMULATED: 8,
     #          KEY_INSTANCES: {"P1" : ["Q5", "Q3"] # 2 instances
     #                          }
     #          },
     #         {"id": "Q35",
     #          KEY_ACCUMULATED: 8,
     #          KEY_INSTANCES:{"P1" : ["Q5", "Q3"],
     #                         "P2" : ["Q3", "Q2", "Q1"]  # 4 instances (Q3 repeated)
     #                          }}]
     return read_json_object(self._in_ag_scores)
    def _parse_source(self, source_path):
        result = read_json_object(path=source_path)

        # Removing wikis
        i = 0
        indexes_to_remove = []
        for i in range(0, len(result)):
            if result[i][KEY_LABEL] is not None:
                if "wiki" in result[i][KEY_LABEL] or "Wiki" in result[i][KEY_LABEL]:
                    indexes_to_remove.append(i)
        for index in reversed(indexes_to_remove):
            del result[index]

        # Adding rank
        i = 1
        for an_elem in result:
            an_elem[KEY_RANKING_WITHIN_SOURCE] = i
            i += 1
        return result
                indexes_to_remove.append(i)
                print "EEEY"
    for index in reversed(indexes_to_remove):
        del json_list[index]


files = [
    "aggregated_class_summary_all_v2.json",
    "aggregated_class_summary_all_v2_Pc2.json",
    "instance_counts_aggregated_class_summary_all_v2.json",
    "instance_counts_aggregated_class_summary_all_v2_Pc2.json"
]

lines = []

json_object = read_json_object(files[0])
remove_wikis(json_object)
for i in range(0, 50):
    # lines.append(str(i + 1) + ". " + json_object[i]["id"] + ":" + json_object[i]["label"] + " ")
    lines.append(str(i + 1) + ". " + json_object[i]["label"] + " ")

for a_path in files[1:]:
    json_object = read_json_object(a_path)
    remove_wikis(json_object)
    for i in range(0, 50):
        # lines[i] += "&" + str(i + 1) + ". " + json_object[i]["id"] + ":" + json_object[i]["label"] + " "
        lines[i] += "&" + str(i + 1) + ". " + json_object[i]["label"] + " "

for i in range(0, 50):
    lines[i] += "\\\\"