当前位置: 首页>>代码示例>>Python>>正文


Python Index.upstream方法代码示例

本文整理汇总了Python中index.Index.upstream方法的典型用法代码示例。如果您正苦于以下问题:Python Index.upstream方法的具体用法?Python Index.upstream怎么用?Python Index.upstream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在index.Index的用法示例。


在下文中一共展示了Index.upstream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import upstream [as 别名]
class DDStorm:
    """ Provides the class for finding differential diagnosis. """

    conf = False

    def __init__(self, comp=False, conf=False):
        """
        Initiate the diagnosis finder.

        Parameters:
        comp - Recompiles the data files if set to True
        conf - Supply a Conf object
        """
        if conf:
            self.conf = conf
        else:
            self.conf = Conf()
        self.compiler = Compile(conf)
        if comp:
            self.compiler.compile()
        self.index = Index(conf)

    def dd(self, symptoms):
        """
        Find the differential diagnosis list.

        Parameter:
        symptom - list of strings containing symptoms

        Return value:
        List of strings containing the differential diagnosis
        """

        # Return empty list if symptom list is empty
        if not symptoms:
            return

        # Find DD of first symptom and discard it
        diff1 = self._getDiff(symptoms.pop(0))

        # Loop through the rest of the list
        for s in symptoms:

            # Find DD of the current item in the list
            diff2 = self._getDiff(s)

            # List for temporary holding the DDs
            temp = []

            # Make both lists the same length by appending empty strings to the end
            if len(diff1) > len(diff2):
                diff2 += [""] * (len(diff1) - len(diff2))
            elif len(diff2) > len(diff1):
                diff1 += [""] * (len(diff2) - len(diff1))

            # Loop over both lists
            for (s1, s2) in zip(diff1, diff2):

                # Add s1 to temp if s1 or any of its upstream ancestor is common to both list
                if (s1 not in temp) and (len(s1) > 0):
                    if s1 in diff2:
                        temp.append(s1)
                    else:
                        us = self.index.upstream(s1)
                        for i in us:
                            if i in diff2:
                                temp.append(i)

                # Add s2 to temp if s2 or any of its upstream ancestor is common to both list
                if (s2 not in temp) and (len(s2) > 0):
                    if s2 in diff1:
                        temp.append(s2)
                    else:
                        us = self.index.upstream(s2)
                        for i in us:
                            if i in diff1:
                                temp.append(i)

            # Copy temp to first list
            diff1 = list(temp)

        return diff1

    def _getDiff(self, symptom):
        """ Return differential diagnosis for a single symptom """
        diff = []
        symptom = symptom.lower().replace("_", " ").replace("-", " ")
        if os.path.isfile(self.conf.get("module_path") + symptom + ".module"):
            with open(self.conf.get("module_path") + symptom + ".module", "r") as mf:
                for line in mf:
                    diff.append(line.strip())
        return diff

    def symptoms(self):
        """
        Return a full list of available symptoms

        Return value:
        List of string containing symptoms
        """
#.........这里部分代码省略.........
开发者ID:agnibho,项目名称:ddstorm,代码行数:103,代码来源:ddstorm.py


注:本文中的index.Index.upstream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。