Example #1
0
def make_from_json(jsonData, filename, removeOld=False):
    if removeOld:
        try:
            os.remove(filename)
        except (OSError):
            pass

    # create the document
    document = Document(filename)

    # set up a mock example
    trn = document.database.transaction()
    with trn:
        document.database.root['documentType'] = jsonData['documentType']
        document.database.root['variety'] = jsonData['variety']

        for i, spanData in enumerate(jsonData['spans']):
            span = Document.persistenceSchema.classes.Span(
                externalID=i, info=spanData['spanInfo'])
            for i, token in enumerate(spanData['tokens']):
                token = Document.persistenceSchema.classes.Token(token)
                try:
                    token.gloss = spanData['lemmas'][i]
                except:
                    pass

                span.addToken(token)

            document.addSpan(span)

    trn.commit()
    document.close()
Example #2
0
    def _ghost(self, oid, state=None):

        if oid is Document:
            return Document()

        kind, tag, content, close = oid
        return kind()
Example #3
0
def apostile_create_post():
    count = session.query(Apostile).filter(Apostile.number == int(request.form['number'])).count()
    if count:
        return render_template('message.html', title='Помилка',
                               msg=f'Апостиль з номером {request.form["number"]} уже існує', **user_config())

    doc = Document(
        country=request.form['country'],
        date=request.form['doc_date'],
        author_name=request.form['person_name'],
        author_info=request.form['person_position'],
        stamp_info=request.form['stamp_info'] if request.form['stamp_info'] else '-/-/-'
    )
    session.add(doc)
    session.flush()

    tr_id, tr_type = find_trusted_by_str(request.form['ap_author'])
    ap = Apostile(
        number=int(request.form['number']),
        date=request.form['ap_date'],
        is_archived=False,
        trusted_id=tr_id, trusted_type=tr_type,
        document_id=doc.id
    )
    session.add(ap)
    session.flush()
    session.commit()

    return redirect(f'/apostile/{ap.id}')
Example #4
0
def save_document(title, session):
    """Create a new document; return it."""
    ## XXX(alexr): need to handle source languages...
    document = Document(title, "bob", "en")
    session.add(document)
    session.commit()
    print("added document:", document)
    return document
 def create_doc(self, content, title, description='', author=''):
     """
     Creates an document.
     :param data: document's properties as json.
     :return:
     """
     doc = Document(content=content, title=title, description=description, author=author)
     self.db.session.add(doc)
     self.db.session.commit()
     return doc
Example #6
0
 def get_doc_by_pid(cls, pid):
     sql = """select * from doc where person_id=?"""
     data = (pid, )
     rows = cls.db.query(sql, data)
     records = []
     for row in rows:
         print(row)
         records.append(
             Document(row[0], row[1], row[2], cls.get_by_doc_id(row[0])))
     return records
Example #7
0
def makeMockDocument():
  try: os.remove(testfile)
  except(OSError): pass
  
  
  document = Document(testfile)  
  
  # set up a mock example
  trn = document.database.transaction()
  with trn:
    for spandata in MockData:
      span = Document.persistenceSchema.classes.Span(externalID = spandata['id'], info = spandata['info'])
      for tok in spandata['tokens']:
        span.addToken(Document.persistenceSchema.classes.Token(tok))
      document.addSpan(span)
    
    # make some constituents, cause why not  
    phrase = Document.persistenceSchema.classes.Constituent()
    phrase.add(document.spans[0].tokens[3])
    phrase.add(document.spans[0].tokens[2])
    phrase.add(document.spans[0].tokens[4])
    
    phrase = Document.persistenceSchema.classes.Constituent()
    phrase.add(document.spans[0].tokens[0])
    phrase.add(document.spans[0].tokens[1])
    phrase.add(document.spans[0].tokens[3])
    phrase.add(document.spans[0].tokens[4])

    phrase = Document.persistenceSchema.classes.Constituent()
    print phrase.refmark
    phrase.add(document.spans[1].tokens[1])
    phrase.add(document.spans[1].tokens[0])
    
    x = Document.persistenceSchema.classes.DependencyRelation(document.spans[0].constituents[0], document.spans[0].tokens[5])
    x = Document.persistenceSchema.classes.DependencyRelation(document.spans[0].tokens[1], document.spans[0].tokens[1])
    
    document.spans[0].tokens[0].variables['PoS'] = 'Noun'
    document.spans[0].tokens[0].variables['Number'] = 'singular'
    document.spans[0].tokens[0].variables['Gender'] = 'masculine'
    document.spans[0].tokens[0].variables['Focus'] = 'yes'
    
    
    mm = Document.persistenceSchema.classes.ReferenceMark()
    document.spans[0].tokens[0].refmark = mm
    document.spans[1].tokens[0].refmark = mm
    phrase.refmark = mm
    
    document.spans[0].tokens[4].refmark = Document.persistenceSchema.classes.ReferenceMark()
    
    
          
  trn.commit()
  
  return document
Example #8
0
 def show(self):
     window = self.window
     while True:
         event, values = window.read()
         if event == "submit":
             doc = Document(None, values['doc'], self.person.id, [])
             doc_id = self.service.add_doc(doc)
             if doc_id > 0:
                 self.make_doc_on_disk(self.person, doc)
             break
         elif event == "reset":
             window.Element("doc").Update(value="")
         else:
             break
     window.Close()
Example #9
0
def load_text(document, name, passcode, doc_owner):
    """ Load the text from the document into database, and create new db object """

    text = document.read()

    document = Document(text=text,
                        name=name,
                        passcode=passcode,
                        doc_owner=doc_owner)

    db.session.add(document)

    db.session.commit()

    return document
Example #10
0
def save_file(fn):
    session = Session()
    title = os.path.basename(fn)
    document = Document(title, "bob", "en")
    session.add(document)
    session.commit()

    docid = document.id

    with open(fn) as infile:
        sentences = []
        for line in infile:
            sent = Sentence(line.strip(), docid)
            sentences.append(sent)
    session.add_all(sentences)
    session.commit()
    print("added document:", document)
Example #11
0
def save_document(title, tags, segments):
    """Given a document title, tags (as a list of strings), all the segments
    (also a list of strings), create a new document and tag it."""
    session = get_session()
    document = Document(title, "bob", "es")
    session.add(document)
    session.commit()
    docid = document.id

    sentences = []
    for (segmentid, s) in segments:
        sent = Sentence(s.strip(), docid)
        sentences.append(sent)
    session.add_all(sentences)
    session.commit()
    for tag in tags:
        tag_document(document, tag)
Example #12
0
    def store_media():
      """Store media object info in datastore.

      Also updates the user-info record to keep count of media objects.

      This function is run as a transaction.
      """
      user_info = UserInfo.get_by_key_name('user:%s' % user_email)
      if user_info is None:
        error_messages.append('User record has been deleted.  '
                              'Try uploading again')
        return

      media = MediaObject(
          parent=user_info,
          owner=user_info,
          blob=blob_info.key(),
          creation=blob_info.creation,
          content_type=blob_info.content_type,
          filename=blob_info.filename,
          size=int(blob_info.size),
          lacks_document=True)

      user_info.media_objects += 1
      db.put(user_info)
      db.put(media)

      if bool(is_doc) and is_doc != "0":
        tag_list = []
        if tags is not None:
          tag_list = [x for x in re.split('\s*,\s*', tags) if x]

        doc = Document(
            parent=user_info,
            owner=user_info,
            pages=[media.key()],
            title=title,
            description=description,
            no_tags=(len(tag_list)==0),
            tags=tag_list)
        db.put(doc)
        media.document = doc.key()
        media.lacks_document = False
        db.put(media)
Example #13
0
def makeMockDocument1():
  try: os.remove(testfile)
  except(OSError): pass
  
  
  document = Document(testfile)  
  
  # set up a mock example
  trn = document.database.transaction()
  with trn:
    for spandata in MockData1:
      span = Document.persistenceSchema.classes.Span(externalID = spandata['id'], info = spandata['info'])
      for tok in spandata['tokens']:
        span.addToken(Document.persistenceSchema.classes.Token(tok))
      document.addSpan(span)
    
  trn.commit()
  
  return document  
Example #14
0
 def post(self):
   user_info = get_user_info()
   if user_info is None:
     self.redirect('/?error_message=%s' % 'log-in required')
   scan_ids = self.request.get_all("media_id")
   scans = MediaObject.get(scan_ids)
   doc = Document(
       parent=user_info,
       owner=user_info,
       pages=[scan.key() for scan in scans],
       title=None,
       description=None)
   def make_doc():
     db.put(doc)
     for scan in scans:
       scan.lacks_document = False
       scan.document = doc.key()
       db.put(scan)
   db.run_in_transaction(make_doc)
   self.redirect(doc.display_url + "?size=1200")
             'bc2ed3d70b2521dc828ebb32db8d8fd954c6b7a9fc63580e601b1863821bc34e'
             ),  # govtech_strong_password
        User(name='Admin',
             username='******',
             password=
             '******'
             ),  # super_duper_whitehacks_strong_password
        Module(code='IS200', name='Software Foundations'),
        Module(code='IS103', name='Computational Thinking'),
        Module(code='IS101', name='Seminar on Information Systems'),
        Module(code='WRIT001', name='Academic Writing'),
        Lesson(module_code='IS200', name='Lesson 01'),
        Lesson(module_code='IS103', name='Lesson 01'),
        Lesson(module_code='IS101', name='Lesson 01'),
        Lesson(module_code='WRIT001', name='Lesson 01'),
        Document(
            lesson_id=1,
            name='Document 01',
            is_draft=False,
            content=
            'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum'
        ),
        Document(lesson_id=4,
                 name='Document Flag',
                 is_draft=True,
                 content='NOTFLAG{youre_almost_there_try_harder}'),
    ]

    db.session.bulk_save_objects(obj)
    db.session.commit()
Example #16
0
 def build(self):
     assert len(self._builders) == 0, self._builders
     assert len(self._states) > 0, self._states
     return Document(self._states)