示例#1
0
    def test_create_table(self):
        rule = Rule(1, None, 2, 5, 0.3, "item")
        CsvGenerator.create_pair_csv([rule], self.file)

        self.file.seek(0)
        self.assertThat(self.file.readline().strip(), Equals("pid1,qid1,pid2,count,probability,context"))
        self.assertThat(self.file.readline().strip(), Equals("1,,2,5,0.3,item"))
    def test_create_table(self):
        file_ = StringIO()
        rule = Rule(1, None, 2, 5, 0.3, "item")
        CsvGenerator.create_pair_csv([rule], file_)

        file_.seek(0)
        assert ('pid1,qid1,pid2,count,probability,context' ==
                file_.readline().strip())
        assert '1,,2,5,0.3,item' == file_.readline().strip()
import time

from propertysuggester.analyzer import CsvGenerator, RuleGenerator
from propertysuggester.parser import CsvReader
from propertysuggester.utils.CompressedFileType import CompressedFileType

if __name__ == "__main__":
    logging.basicConfig(level=20)  # Print logging.info

    parser = argparse.ArgumentParser(
        description="this program generates a correlation-table from "
        "the csv-dump")
    parser.add_argument("input",
                        help="The CSV input file (wikidata triple)",
                        type=CompressedFileType('rb'))
    parser.add_argument("output",
                        help="The CSV output file (default=sys.stdout)",
                        default=sys.stdout,
                        nargs='?',
                        type=CompressedFileType('wb'))
    args = parser.parse_args()

    start = time.time()
    logging.info("computing table")
    rules = RuleGenerator.compute_rules(CsvReader.read_csv(args.input))
    logging.info("writing csv")
    CsvGenerator.create_pair_csv(rules, args.output)
    logging.info("done - {0:.2f}s".format(time.time() - start))
    logging.info("now import this csv file with "
                 "PropertySuggester/maintenance/UpdateTable.php")
示例#4
0
import logging
import argparse
import sys
import time

from propertysuggester.analyzer import CsvGenerator, RuleGenerator
from propertysuggester.parser import CsvReader
from propertysuggester.utils.CompressedFileType import CompressedFileType

if __name__ == "__main__":
    logging.basicConfig(level=20) # Print logging.info

    parser = argparse.ArgumentParser(description="this program generates a correlation-table from the csv-dump")
    parser.add_argument("input", help="The CSV input file (wikidata triple)", type=CompressedFileType('rb'))
    parser.add_argument("output", help="The CSV output file (default=sys.stdout)", default=sys.stdout, nargs='?',
                        type=CompressedFileType('wb'))
    args = parser.parse_args()

    start = time.time()
    logging.info("computing table")
    rules = RuleGenerator.compute_rules(CsvReader.read_csv(args.input))
    logging.info("writing csv")
    CsvGenerator.create_pair_csv(rules, args.output)
    logging.info("done - {0:.2f}s".format(time.time()-start))
    logging.info("now import this csv file with PropertySuggester/maintenance/UpdateTable.php")