]>
Softwares of Agnibho - ddstorm.git/blob - ddstorm.py
4 DDStorm is a python application for finding differential diagnosis for
5 a given list of symptoms.
8 Copyright (c) 2015 Agnibho Mondal
11 This file is part of DDStorm.
13 DDStorm is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 DDStorm is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with DDStorm. If not, see <http://www.gnu.org/licenses/>.
30 from compile import Compile
32 from index
import Index
35 ''' Provides the class for finding differential diagnosis. '''
38 def __init__(self
, comp
=False, conf
=False):
40 Initiate the diagnosis finder.
43 comp - Recompiles the data files if set to True
44 conf - Supply a Conf object
50 self
.compiler
=Compile(conf
)
52 self
.compiler
.compile()
53 self
.index
=Index(conf
)
55 def dd(self
, symptoms
):
57 Find the differential diagnosis list.
60 symptom - list of strings containing symptoms
63 List of strings containing the differential diagnosis
66 # Return empty list if symptom list is empty
70 # Find DD of first symptom and discard it
71 diff1
=self
._getDiff
(symptoms
.pop(0))
73 # Loop through the rest of the list
76 # Find DD of the current item in the list
77 diff2
=self
._getDiff
(s
)
79 # List for temporary holding the DDs
82 # Make both lists the same length by appending empty strings to the end
83 if(len(diff1
)>len(diff2
)):
84 diff2
+=[""]*(len(diff1
)-len(diff2
))
85 elif(len(diff2
)>len(diff1
)):
86 diff1
+=[""]*(len(diff2
)-len(diff1
))
88 # Loop over both lists
89 for (s1
, s2
) in zip(diff1
, diff2
):
91 # Add s1 to temp if s1 or any of its upstream ancestor is common to both list
92 if((s1
not in temp
) and (len(s1
)>0)):
96 us
=self
.index
.upstream(s1
)
101 # Add s2 to temp if s2 or any of its upstream ancestor is common to both list
102 if((s2
not in temp
) and (len(s2
)>0)):
106 us
=self
.index
.upstream(s2
)
111 # Copy temp to first list
116 def _getDiff(self
, symptom
):
117 ''' Return differential diagnosis for a single symptom '''
119 symptom
=symptom
.lower().replace("_"," ").replace("-", " ")
120 if(os
.path
.isfile(self
.conf
.get("module_path")+symptom
+".module")):
121 with
open(self
.conf
.get("module_path")+symptom
+".module", "r") as mf
:
123 diff
.append(line
.strip())
128 Return a full list of available symptoms
131 List of string containing symptoms
134 for n
in os
.listdir(self
.conf
.get("module_path")):
135 symp
.append(os
.path
.splitext(os
.path
.basename(n
))[0].capitalize())
140 Find differential diagnosis in command line mode.
141 Accepts symptoms as command line arguments. Prints a list of
142 avialable symptoms if called without any argument.
144 Command line arguments:
145 A list of symptoms separated by space
149 for d
in s
.dd(sys
.argv
[1:]):
152 for s
in s
.symptoms():
155 if(__name__
=="__main__"):