コード例 #1
0
ファイル: list_loader.py プロジェクト: Ram-N/OM-API-Utilities
def  create_item_dicts(textlist):
  '''
  Each line in CSV file is a new item. It has to have its mandatory fields
  and optionally, any of the other item properties for that list format
  '''

  dictslist = []


  WORD = 'word'
  POS = 'pos'
  DEFINITION = 'defn'
  SENTENCE = 'sentence'
  ITEM_PROPERTIES = (WORD,POS, DEFINITION,SENTENCE)

  for r in textlist:
    print r
    if r[0].rstrip(" ").lower() =="item":
      idict = {}
      for index, el in enumerate(r):                
        if el in ITEM_PROPERTIES:
          om_utils.add_to_dict(idict,el,r,index) #will add the token next to curr index        

      if not WORD in idict:
        print("WORD  property not specified in CSV. ITEM  cannot be created without this mandatory field")
      if not DEFINITION in idict:
        print("DEFN  property not specified in CSV. ITEM  cannot be created without this mandatory field")

      dictslist.append(idict)


  return dictslist # a list of idicts
コード例 #2
0
def  create_item_dicts(textlist):
  '''
  Each line in CSV file is a new user. It has to have its mandatory fields
  and optionally, any of the other user properties
  '''

  dictslist = []


  USERNAME = '******'
  PASSWORD = '******'
  NAME  =  'name'
  TYPE = 'type'
  USER_PROPERTIES = (USERNAME, PASSWORD, NAME, TYPE)

  for r in textlist:
 #   print r
    if r[0].rstrip(" ").lower() =="user":
      idict = {}
      for index, el in enumerate(r):                
        if el in USER_PROPERTIES:
          om_utils.add_to_dict(idict,el,r,index) #will add the token next to curr index        

      if not TYPE in idict:
        print("TYPE  property not specified in CSV. USER cannot be created without this mandatory field")
      if not USERNAME in idict:
        print("USERNAME  property not specified in CSV. USER  cannot be created without this mandatory field")
      if not PASSWORD in idict:
        print("PASSWORD property not specified in CSV. USER  cannot be created without this mandatory field")

      dictslist.append(idict)


  return dictslist # a list of idicts
コード例 #3
0
def create_list_dict(allRows):
    '''
    Read all lines that begin with List and if a format is found, store it.
    Return False if there is no format, or if format is unrecognized
    '''
    ldict = {}
    # title || Name of the list ||
    # description || Short list description.
    # standard || String code representing the list standard. Example: "L.7.2".
    # section || Numerical sub-section of the standard.

    TITLE = 'title'
    DESCRIPTION = 'description'
    FORMAT = 'format'
    GRADE = 'grade'
    SECTION = 'section'
    STANDARD = 'standard'
    DUMMY = 'dummy12sger434'
    LIST_PROPERTIES = (TITLE, DESCRIPTION, FORMAT, SECTION, STANDARD)
    LIST_INTEGER_PROPERTIES = (GRADE, DUMMY)

    #    if not 'format' in row:
    #        print('Format type must be specified for new lists.')

    #    print("useful lines in List file",  len(allRows))
    for row in allRows:
        #        print row[0]
        if row[0].rstrip(" ").lower() == "list":
            for index, item in enumerate(row):
                if item in LIST_PROPERTIES:
                    om_utils.add_to_dict(
                        ldict, item.lower(), row,
                        index)  #will add the token next to curr index

                # grade || Intended grade level of the list. Number between 0 (K) and 8.
                if item in LIST_INTEGER_PROPERTIES:
                    # print("item %s" % item)
                    om_utils.add_to_dict_as_int(ldict, item.lower(), row,
                                                index)

    if not "format" in ldict:
        print(
            "List format property not specified in CSV. List cannot be created without this mandatory field"
        )

    return ldict
コード例 #4
0
ファイル: list_loader.py プロジェクト: Ram-N/OM-API-Utilities
def create_list_dict(allRows):
    '''
    Read all lines that begin with List and if a format is found, store it.
    Return False if there is no format, or if format is unrecognized
    '''
    ldict = {}
# title || Name of the list || 
# description || Short list description.
# standard || String code representing the list standard. Example: "L.7.2".
# section || Numerical sub-section of the standard.

    TITLE = 'title'
    DESCRIPTION = 'description'
    FORMAT = 'format'
    GRADE = 'grade'
    SECTION = 'section'
    STANDARD = 'standard'
    DUMMY = 'dummy12sger434'
    LIST_PROPERTIES = (TITLE, DESCRIPTION, FORMAT,SECTION,STANDARD)
    LIST_INTEGER_PROPERTIES = (GRADE, DUMMY)

#    if not 'format' in row:
#        print('Format type must be specified for new lists.')
    



#    print("useful lines in List file",  len(allRows))
    for row in allRows:
#        print row[0]
        if row[0].rstrip(" ").lower() == "list":
            for index, item in enumerate(row):                
                if item in LIST_PROPERTIES:
                  om_utils.add_to_dict(ldict,item.lower(),row,index) #will add the token next to curr index
                            
                # grade || Intended grade level of the list. Number between 0 (K) and 8.
                if item in LIST_INTEGER_PROPERTIES:
                  # print("item %s" % item)
                  om_utils.add_to_dict_as_int(ldict,item.lower(),row,index)

    if not "format" in ldict:
      print("List format property not specified in CSV. List cannot be created without this mandatory field")


    return ldict
コード例 #5
0
def create_item_dicts(textlist):
    '''
  Each line in CSV file is a new user. It has to have its mandatory fields
  and optionally, any of the other user properties
  '''

    dictslist = []

    USERNAME = '******'
    PASSWORD = '******'
    NAME = 'name'
    TYPE = 'type'
    USER_PROPERTIES = (USERNAME, PASSWORD, NAME, TYPE)

    for r in textlist:
        #   print r
        if r[0].rstrip(" ").lower() == "user":
            idict = {}
            for index, el in enumerate(r):
                if el in USER_PROPERTIES:
                    om_utils.add_to_dict(
                        idict, el, r,
                        index)  #will add the token next to curr index

            if not TYPE in idict:
                print(
                    "TYPE  property not specified in CSV. USER cannot be created without this mandatory field"
                )
            if not USERNAME in idict:
                print(
                    "USERNAME  property not specified in CSV. USER  cannot be created without this mandatory field"
                )
            if not PASSWORD in idict:
                print(
                    "PASSWORD property not specified in CSV. USER  cannot be created without this mandatory field"
                )

            dictslist.append(idict)

    return dictslist  # a list of idicts
コード例 #6
0
def create_item_dicts(textlist):
    '''
  Each line in CSV file is a new item. It has to have its mandatory fields
  and optionally, any of the other item properties for that list format
  '''

    dictslist = []

    WORD = 'word'
    POS = 'pos'
    DEFINITION = 'defn'
    SENTENCE = 'sentence'
    ITEM_PROPERTIES = (WORD, POS, DEFINITION, SENTENCE)

    for r in textlist:
        print r
        if r[0].rstrip(" ").lower() == "item":
            idict = {}
            for index, el in enumerate(r):
                if el in ITEM_PROPERTIES:
                    om_utils.add_to_dict(
                        idict, el, r,
                        index)  #will add the token next to curr index

            if not WORD in idict:
                print(
                    "WORD  property not specified in CSV. ITEM  cannot be created without this mandatory field"
                )
            if not DEFINITION in idict:
                print(
                    "DEFN  property not specified in CSV. ITEM  cannot be created without this mandatory field"
                )

            dictslist.append(idict)

    return dictslist  # a list of idicts