Ejemplo n.º 1
0
    def __init__(self, rdf_node):
        global _node_json_number
        subj_str = str(rdf_node)

        entity_label, entity_graphic_class, entity_id = lib_naming.ParseEntityUri(
            subj_str, long_display=False, force_entity_ip_addr=None)

        self.m_label = entity_label.strip()
        self.m_class = entity_graphic_class

        array_graph_params = lib_patterns.TypeToGraphParams(self.m_class)

        # "Graphic_shape","Graphic_colorfill","Graphic_colorbg","Graphic_border","Graphic_is_rounded"
        self.m_color = array_graph_params[1]

        # TODO: Display the doc in the module with FromModuleToDoc(importedMod,filDfltText):
        self.m_info_list = [entity_graphic_class]
        self.m_info_dict = dict()
        self.m_index = _node_json_number

        the_survol_url = lib_util.survol_unescape(rdf_node)
        self.m_survol_url = the_survol_url
        self.m_survol_universal_alias = lib_exports.NodeToUniversalAlias(
            rdf_node)

        _node_json_number += 1  # One more node.
Ejemplo n.º 2
0
    def __init__(self, rdf_node):
        global NodeJsonNumber
        subj_str = str(rdf_node)

        (entity_label, entity_graphic_class,
         entity_id) = lib_naming.ParseEntityUri(subj_str,
                                                longDisplay=False,
                                                force_entity_ip_addr=None)

        self.m_label = entity_label.strip()
        self.m_class = entity_graphic_class

        arrayGraphParams = lib_patterns.TypeToGraphParams(self.m_class)

        # "Graphic_shape","Graphic_colorfill","Graphic_colorbg","Graphic_border","Graphic_is_rounded"
        self.m_color = arrayGraphParams[1]

        # TODO: Display the doc in the module with FromModuleToDoc(importedMod,filDfltText):
        self.m_info_list = [entity_graphic_class]
        self.m_info_dict = dict()
        self.m_index = NodeJsonNumber

        the_survol_url = lib_util.survol_HTMLParser().unescape(rdf_node)
        # Hack, specific to OVH.
        the_survol_url = the_survol_url.replace(
            "primhillcomputers.com:80/survol/survolcgi",
            "primhillcomputers.com:80/cgi-bin/survol/survolcgi")
        self.m_survol_url = the_survol_url
        self.m_survol_universal_alias = NodeToUniversalAlias(rdf_node)

        NodeJsonNumber += 1  # One more node.
Ejemplo n.º 3
0
def _entity_array_to_label(entity_type, entity_ids_arr):
    """This fetches in the module of the class, a function called "EntityName"."""
    func_entity_name = lib_util.HierarchicalFunctionSearch(entity_type, "EntityName")

    if func_entity_name:
        entity_name = func_entity_name(entity_ids_arr)
        return entity_name

    # General case of a URI created by us and for us.
    ent_ids_joined = ",".join(entity_ids_arr)
    if lib_patterns.TypeToGraphParams(entity_type) is None:
        # If the type does not have a special color, add its name.
        return "%s (%s)" % (ent_ids_joined, entity_type)
    else:
        return ent_ids_joined
Ejemplo n.º 4
0
def EntityArrToLabel(entity_type, entity_ids_arr):
    funcEntityName = lib_util.HierarchicalFunctionSearch(
        entity_type, "EntityName")

    if funcEntityName:
        entity_name = funcEntityName(entity_ids_arr)
        return entity_name

    # General case of a URI created by us and for us.
    ent_ids_joined = ",".join(entity_ids_arr)
    if lib_patterns.TypeToGraphParams(entity_type) is None:
        # If the type does not have a special color, add its name.
        return "%s (%s)" % (ent_ids_joined, entity_type)
    else:
        return ent_ids_joined
Ejemplo n.º 5
0
def _objects_triplets(dict_class_subj_prop_obj):
    """Group objects by class.
    Display list of classes with an index and a link to the class."""

    # No need to use natural sort, because these are no filenames or strings containing numbers.
    for entity_graphic_class in sorted(dict_class_subj_prop_obj):
        url_class = lib_util.EntityClassUrl(entity_graphic_class)
        url_class_with_mode = _url_in_html_mode(url_class)
        dict_subj_prop_obj = dict_class_subj_prop_obj[entity_graphic_class]

        array_graph_params = lib_patterns.TypeToGraphParams(
            entity_graphic_class)
        # "Graphic_shape","Graphic_colorfill","Graphic_colorbg","Graphic_border","Graphic_is_rounded"
        color_class = array_graph_params[1]

        yield url_class_with_mode, entity_graphic_class, color_class, dict_subj_prop_obj
Ejemplo n.º 6
0
def DispClassObjects(dictSubjPropObj):
    listPropsTdDoubleColSpan = [
        pc.property_information, pc.property_rdf_data_nolist2,
        pc.property_rdf_data_nolist1
    ]

    WrtAsUtf('<table class="class_objects">')

    # The subjects must be sorted by their title.
    lstTuplesSubjects = []
    for aSubj in dictSubjPropObj:
        subj_str = str(aSubj)
        (subj_title, entity_graphic_class,
         entity_id) = lib_naming.ParseEntityUri(subj_str)
        lstTuplesSubjects.append(
            (aSubj, subj_str, subj_title, entity_graphic_class, entity_id))

    # Sorted by the title of the subject, which is the third value of the tuple.
    lib_util.natural_sort_list(lstTuplesSubjects, key=lambda tup: tup[2])

    # Now it iterates on the sorted list.
    # This reuses all the intermediate values.
    for aSubj, subj_str, subj_title, entity_graphic_class, entity_id in lstTuplesSubjects:
        dictPred = dictSubjPropObj[aSubj]

        arrayGraphParams = lib_patterns.TypeToGraphParams(entity_graphic_class)
        # "Graphic_shape","Graphic_colorfill","Graphic_colorbg","Graphic_border","Graphic_is_rounded"
        colorClass = arrayGraphParams[1]

        # Total number of lines.
        cntPreds = 0
        for aPred in dictPred:
            lstObjs = dictPred[aPred]
            cntPreds += len(lstObjs)

        mustWriteColOneSubj = True

        subj_str_with_mode = UrlInHtmlMode(subj_str)

        # The predicates, i.e. the properties associated a subject with an object,
        # must be alphabetically sorted.
        for aPred in lib_util.natural_sorted(dictPred):
            lstObjs = dictPred[aPred]

            predStr = lib_exports.AntiPredicateUri(str(aPred))
            cntObjs = len(lstObjs)
            mustWriteColOnePred = True

            # The objects must be sorted by title.
            lstTuplesObjs = []
            for anObj in lstObjs:
                obj_str = str(anObj)
                obj_str = DesHex(obj_str)
                obj_title = lib_naming.ParseEntityUri(obj_str)[0]
                lstTuplesObjs.append((anObj, obj_str, obj_title))

            # Sorted by the title of the object, which is the third value of the tuple.
            lib_util.natural_sort_list(lstTuplesObjs, key=lambda tup: tup[2])

            for anObj, obj_str, obj_title in lstTuplesObjs:

                WrtAsUtf('<tr bgcolor="%s">' % colorClass)

                if mustWriteColOneSubj:
                    WrtAsUtf(
                        '<td valign="top" rowspan="%s"><a href="%s">%s</a></td>'
                        % (str(cntPreds), subj_str_with_mode, subj_title))
                    mustWriteColOneSubj = False

                if mustWriteColOnePred:
                    if aPred not in listPropsTdDoubleColSpan:
                        WrtAsUtf('<td valign="top" rowspan="%s">%s</td>' %
                                 (str(cntObjs), predStr))
                    mustWriteColOnePred = False

                if aPred in listPropsTdDoubleColSpan:
                    colSpan = 2
                else:
                    colSpan = 1

                dispMimeUrls = True

                WrtAsUtf('<td colspan="%d">' % (colSpan))
                if dispMimeUrls:
                    if lib_kbase.IsLink(anObj):
                        objStrClean = lib_util.UrlNoAmp(obj_str)
                        mimeType = lib_mime.GetMimeTypeFromUrl(objStrClean)
                        if mimeType:
                            if mimeType.startswith("image/"):
                                WrtAsUtf(
                                    """<a href="%s"><img src="%s" alt="%s" height="42" width="42"></a>"""
                                    % (obj_str, obj_str, obj_title))
                            else:
                                WrtAsUtf("""<a href="%s">%s</a>""" %
                                         (obj_str, obj_title))
                        else:
                            url_with_mode = lib_util.AnyUriModed(
                                obj_str, "html")
                            WrtAsUtf("""<a href="%s">%s</a>""" %
                                     (url_with_mode, obj_title))
                    else:
                        WrtAsUtf('%s' % (obj_str))
                else:
                    if lib_kbase.IsLink(anObj):
                        url_with_mode = UrlInHtmlMode(obj_str)
                        WrtAsUtf('<a href="%s">%s</a>' %
                                 (url_with_mode, obj_title))
                    else:
                        WrtAsUtf('%s' % (obj_str))

                WrtAsUtf("</td>")

                WrtAsUtf("</tr>")

    WrtAsUtf(" </table>")