示例#1
0
 def test1ParseGoverment(self):
     f = "src/pysumo/data/Government.kif"
     o = Ontology(f, lpath=self.tmpdir)
     atexit.unregister(o.action_log.log_io.flush_write_queues)
     with open(o.path) as f:
         parser.kifparse(f, o)
     o.action_log.log_io.flush_write_queues()
示例#2
0
    def accept(self):
        """ 
        Commit the input and dispose the dialog.
        """
        path = self.ontologyPath.text()
        if not os.path.exists(path):
            os.makedirs(path)
        path = ''.join([path, '/', self.ontologyName.text(), '.kif'])
        path = os.path.normpath(path)

        # create the ontology file.
        try:
            with open(path, 'x') as f:
                f.close()
        except FileExistsError:
            ret = QMessageBox.warning(
                self, "The ontology file already exists.",
                "Do you want to override the existing ontology file?",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if ret == QMessageBox.Yes:
                with open(path, 'w') as f:
                    f.close()
            elif ret == QMessageBox.No:
                return
            else:
                raise RuntimeError
        ontology = Ontology(path, name=self.ontologyName.text())
        self.parent().addOntology(ontology)
        super(NewOntologyDialog, self).accept()
示例#3
0
    def accept(self):
        """
        Commit the input and dispose the dialog.
        """
        path = self.path.text()
        if not os.path.exists(path):
            os.makedirs(path)
        path += "/"
        path += self.name.text()
        path += ".kif"
        path = os.path.normpath(path)

        # create the ontology file.
        try:
            with open(path, 'x') as f:
                f.close()
        except FileExistsError:
            ret = QMessageBox.warning(
                self, "The ontology file already exists.",
                "Do you want to override the existing ontology file?",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if ret == QMessageBox.Yes:
                with open(path, 'w') as f:
                    f.close()
            elif ret == QMessageBox.No:
                return
            else:
                raise RuntimeError
        ontology = Ontology(path, name=self.name.text(), url=self.url.text())
        # download the ontology (user must save to store ontology on disk)
        updater.update(
            ontology, lambda x: self.parent().addOntology(
                ontology, newversion=x.getvalue().decode('utf8')))
        super(OpenRemoteOntologyDialog, self).accept()
示例#4
0
 def setUp(self):
     self.tmpdir = mkdtemp()
     self.sumo = Ontology('src/pysumo/data/Merge.kif',
                          name='SUMO',
                          lpath=self.tmpdir)
     atexit.unregister(self.sumo.action_log.log_io.flush_write_queues)
     with open(self.sumo.path) as f:
         self.kif = parser.kifparse(f, self.sumo)
     self.indexabstractor = IndexAbstractor()
     self.indexabstractor.update_index(self.kif)
示例#5
0
 def test6MultipleOntologies(self):
     milo = Ontology('src/pysumo/data/MILO.kif', lpath=self.tmpdir)
     atexit.unregister(milo.action_log.log_io.flush_write_queues)
     with open(milo.path) as f:
         milo_kif = parser.kifparse(f, milo)
     merged_asts = parser.astmerge((self.kif, milo_kif))
     search_results = self.indexabstractor.search('rangesubclass')[
         self.sumo]
     self.indexabstractor.update_index(merged_asts)
     new_results = self.indexabstractor.search('rangesubclass')[self.sumo]
     self.assertListEqual(search_results, new_results)
     milo.action_log.log_io.flush_write_queues()
示例#6
0
 def restoreRecentOntologyHistory(self):
     """
     Restore the recent opened ontologies and add them to index.
     """
     size = self.beginReadArray("RecentOntologies")
     for i in range(size):
         self.setArrayIndex(i)
         name = self.value("name")
         path = self.value("path")
         url = self.value("url")
         lpath = self.value("lpath")
         ontology = Ontology(path=path, name=name, url=url, lpath=lpath)
         self.mainwindow.addRecentOntology(ontology)
     self.endArray()
示例#7
0
 def _openLocalOntology_(self):
     """
     QT Slot which handles the open local ontology action when it is triggered.
     """
     defPath = self.getDefaultOutputPath()
     x, y = QFileDialog.getOpenFileName(self, "Open Ontology File", defPath,
                                        "SUO KIF Files (*.kif)")
     if x == '' and y == '':
         return
     filepath = x
     filename = os.path.split(filepath)[1]
     filename = os.path.splitext(filename)[0]
     ontology = Ontology(filepath, filename)
     self.addOntology(ontology)
示例#8
0
 def test7GetCompletions(self):
     completions = self.indexabstractor.get_completions()
     self.assertIn('TwoDimensionalFigure', completions)
     self.assertEqual(len(completions), 1168)
     milo = Ontology('src/pysumo/data/MILO.kif', lpath=self.tmpdir)
     atexit.unregister(milo.action_log.log_io.flush_write_queues)
     with open(milo.path) as f:
         milo_kif = parser.kifparse(f, milo)
     merged_asts = parser.astmerge((self.kif, milo_kif))
     self.indexabstractor.update_index(merged_asts)
     completions = self.indexabstractor.get_completions()
     self.assertIn('TwoDimensionalFigure', completions)
     self.assertIn('SubstringFn', completions)
     self.assertEqual(len(completions), 3228)
     milo.action_log.log_io.flush_write_queues()
示例#9
0
 def test0ParseSerilize(self):
     tempd = mkdtemp()
     out1 = "/".join([tempd, "out1"])
     out2 = "/".join([tempd, "out2"])
     f = "src/pysumo/data/Merge.kif"
     o = Ontology(f, lpath=self.tmpdir)
     atexit.unregister(o.action_log.log_io.flush_write_queues)
     with open(o.path) as f:
         a = parser.kifparse(f, o)
     self.assertNotEqual(a.children, [])
     with open(out1, 'w') as f:
         parser.kifserialize(a, o, f)
     with open(o.path) as f:
         a = parser.kifparse(f, o)
     with open(out2, 'w') as f:
         parser.kifserialize(a, o, f)
     ret = subprocess.call(["diff", out1, out2])
     rmtree(tempd)
     assert ret == 0
     o.action_log.log_io.flush_write_queues()
示例#10
0
#!/usr/bin/env python3

import sys
sys.path.append('../src')
from tempfile import mkdtemp

import pysumo
from pysumo import parser
from pysumo.indexabstractor import *
from pysumo.syntaxcontroller import Ontology

sumo = Ontology('../src/pysumo/data/Merge.kif', name='SUMO')
with open(sumo.path) as f:
    mergeKif = parser.kifparse(f, sumo)
index = IndexAbstractor()
index.update_index(mergeKif)

EntitySubclassGraph = index.get_graph([(0, 'subclass')], root='Entity')
print('In "subclass" relation with "Entity":')
print(EntitySubclassGraph.nodes)

BinaryPredicateInstanceGraph = index.get_graph([(0, 'instance')],
                                               root='BinaryPredicate')
print('\nIn "instance" relation with "BinaryPredicate":')
print(BinaryPredicateInstanceGraph.nodes)