예제 #1
0
    def _chapter_details(self, refs, entry):
        """Get details specific to chapter."""

        # get chapter details
        try:
            pages = refs[entry].fields['pages']
        except KeyError:
            pages = '?'

        # get details for book containing chapter
        try:
            book_title = refs[entry].fields['booktitle']
        except KeyError:
            book_title = None
        try:
            publisher = refs[entry].fields['publisher']
        except KeyError:
            publisher = '?'
        try:
            location = refs[entry].fields['address']
        except KeyError:
            location = "?"

        # try to match details for book containing chapter to known book
        if book_title:
            q = db.Query(self.db_file)
            match = q.search("texts", "title", book_title)
            if match: book_key = match[0][0]
            else: book_key = str(entry) + "<BOOK"
        else: book_key = str(entry) + "<BOOK"

        return (pages, book_key, publisher, location)
예제 #2
0
    def __init__(self,
                 db_file,
                 key='?',
                 publication_year='?',
                 title='?',
                 text_type='?',
                 doi='?',
                 references=[],
                 referals=[],
                 creators=[{
                     "surname": "?",
                     "initial": "?",
                     "role": "?"
                 }]):
        """Initializes Text instance.
        
        Args:
            db_file (string): file location of database
            key (string): in BetterBibTex format [authForeIni][authEtAl][year].
            publication_year (string): YYYY
            title (string)
            text_type (string)
            references (list): texts cited by this Text.
            referals (list): texts which cite this Text.
            creators (JSON, ie. list of dicts): 
                                specifying 'surname', 'initial' and 'role'."""

        self.db_file = db_file
        self.q = db.Query(db_file)
        self.creators = creators
        for creator in creators:
            # ~ Person(creator.surname, creator.initial).works.append(self) # or something...
            pass
        self.publication_year = publication_year

        self.key = key
        if self.key == '?':
            if len(self.creators) == 1:
                surnames = self.creators[0]["surname"]
            surnames = '?'
            if len(self.creators) == 2:
                surnames = self.creators[0]["surname"] + self.creators[1][
                    "surname"]
            if len(self.creators) > 2:
                surnames = self.creators[0] + "EtAl"
            proposed_key = self.creators[0][
                "initial"] + surnames + self.publication_year
            # TODO: add 'a','b','c' etc. to proposed_key if key exists and text is new

        self.references = references

        self.referals = referals
        self.title = title
        if text_type in self.text_types:
            self.text_type = text_type
        else:
            print(f"'{text_type}' not recognized as valid text.type")
            self.text_type = '?'
        self.doi = doi
        self.save()
예제 #3
0
def api(key, radius):
    """API to return citation graph"""

    print(f"API called for {key}")

    db_file = os.path.join(sys.path[0], 'citation_graph.db')
    q = db.Query(db_file)
    graph_data = q.json_graph(key, int(radius))

    return jsonify(graph_data)
예제 #4
0
    def __init__(self, db_file, surname="?", initial="?"):
        """Initialize Creator instance."""

        self.db_file = db_file
        self.q = db.Query(db_file)
        self.surname = surname
        self.initial = initial
        self.key = self.initial + self.surname
        self.works = []
        self.save()
예제 #5
0
    def __init__(self, db_file, citing, cited):
        """
        Initialize Citation instance.
        
        Args:
            citing (string): key of citing text.
            cited (string): key of cited text.
        """

        self.db_file = db_file
        self.q = db.Query(db_file)
        self.key = citing + '-->' + cited
        self.citing = citing
        self.cited = cited

        self.save()
예제 #6
0
    def db_commands(self):
        """
        Tests that database commands from ../db_commands.py are working as expected.
        
        Args:
            file (string): file location for db_commands.py
        """

        self.tests += 1

        details = ""

        try:
            q = db.Query(os.path.join(sys.path[0], 'citation_graph.db'))
            assert q.test() == "connected"
            details += '\n>>>Connection working'
            q.create_table('test_table', ('key', 'other_column'))
            details += '\n>>>create_table() working'
            q.save_row_to_table('test_table', ('test_key', 'testing_testing'))
            details += '\n>>>save_row_to_table() working'
            assert q.search('test_table', 'key',
                            'test_key')[0] == ('test_key', 'testing_testing')
            details += '\n>>>search() working'
            q.remove_row('test_table', 1)
            details += '\n>>>remove_row() working'
            assert len(q.search('test_table', 'key', 'test_key')) == 0
            q.save_row_to_table('test_table', ('test_key', 'testing_testing'),
                                allow_duplicate=True)
            q.save_row_to_table('test_table', ('test_key', 'testing_testing'),
                                allow_duplicate=True)
            assert len(q.search('test_table', 'key', 'test_key')) == 2
            details += '\n>>>testing remove_duplicate_rows()'
            q.remove_duplicate_rows('test_table', 'test_key')
            assert len(q.search('test_table', 'key', 'test_key')) == 1
            details += '\n>>>remove_duplicate_rows() working'
            q.drop_table('test_table')
            details += '\n>>>drop_table() working'
            self.success += 1
            result = "\nTest Successful: Database Commands working as expected."
        except:
            e = sys.exc_info()
            print(f"\n\n\nERROR: {e}")
            result = "\nTest Failed: Database Commands not working as expected."
            result += details
        print(result)
        return result