我有一个访问文件,其中包含有关图书的详细信息,我需要获取详细信息并将其转换为marc记录,反之亦然。怎么做最好的方法呢?
答案 0 :(得分:1)
我在C#中发布了我的MARC实现代码。要进行实际编码,您需要最有可能参考美国国会图书馆的MARC页面。
http://sourceforge.net/projects/marclibrary/
如果您使用图书馆,请随时向我提供反馈!
标记
答案 1 :(得分:0)
我怀疑你会找到任何可以让你在一个跳跃中的东西。您最好的选择很可能是使用您最喜欢的数据访问技术从Access读取记录,然后将其转换为讲MARC的内容。我没有用它,但MARCNet project看起来很有希望。 MARC format并不难以手工实现(它只是文本平面文件的核心),但很大程度上取决于你最终会与谁交谈,以及他们是多么挑剔。
答案 2 :(得分:0)
FWIW,这是我十年前写的一些代码,我使用了进程MARC并将它们放入访问数据库。
自从我看到这个以来已经很长时间了,但我想这可能是一个开始:
'IMPORTANT NOTE: The Marc Record's directory (this is a feature located within a Marc
' Record used to parse the record) uses option base 0 to list
' its positions for the varying fields. (See http://lcweb.loc.gov/marc)
' For example, in "Chumbawumba" the letter "C" would be in the zero position
' On the other hand, VB's Instr() function uses option base 1 to
' determine positions in a variable. ("C" is in position 1).
' Code has been adjusted to reflect this difference.
Option Explicit
Option Base 0
Const Marc21_Blank = " " 'Chr(32) Hex 20
Const Marc21_Delimiter = "" 'Chr(31) Hex 1F
Const Marc21_FieldTerminator = "" 'Chr(30) Hex 1E
Const Marc21_RecordTerminator = "" 'Chr(29) Hex 1D
Const Marc21_FillChar = "|" 'Chr(124) Hex 7C
Const Marc21_DirLength = 12 'Length of 1 direcotry Entry (option base 1)
Const Marc21_DirLengthOfFieldPos = 3 'Where the "Length of Field" number can be found in
'one directory entry (by MARC definition)
Const Marc21_DirLengthOfFieldLength = 4 'The physical length of the "Length of Field" entry
'Found in the directory
Const Marc21_DirStartingPos = 7 'Where the "Length of Field" number can be found in
'one directory entry (by MARC definition)
Const Marc21_DirStartingPosLength = 5 'The physical length of the "Length of Field" entry
'Found in the directory
Const Marc21_DirTagLength = 3 'The physical length of the "Length of Field" entry
Const Marc21_LdrLength = 24 'Length of Leader (option base 1)
Const Marc21_PositionAdjustment = 1 'Adjustment constant for Marc record (see note at top of module)
Const Marc21_FieldTerminatorPos = 1 'Represents a place for field terminator
Const Marc21_MaxControlFieldTagValue = 9 'Tags for control fields range from "001" to "009"
Const Marc21_IndicatorLength = 1 'Length of indicator
Const Marc21_MovePastIndicators = 3 'After indicators are stored in a variable field
'we should move past them to the new starting position
'This new position will be a delimeter for a variable field
Const Marc21_MovePastSubfieldCode = 2 'Used to move past the delimeter and subfield code in a varible field
'Const Marc21_FieldCount = 1 'Number of fields in Directory (option base 0)
Dim mrsLeaders As Recordset 'Recordset storing Leaders from the Marcs Imported
Dim mrsTags As Recordset 'Recordset storing the Tags
Dim mrsFields As Recordset 'Recordset storing the different variable fields in the data
'***********************************************************************************************************************
' PROCEDURE: ProcessRecord_S
'
' PURPOSE: From the text file passed, this sub will parse the Marc records
' and individually send them to the subsequent modules for further parsing
'
'PARAMETERS: sFile -- contains full path and filename of text file passed
'
'
' Date: Name: Description:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 03/06/01 Ray Initial Creation
'***********************************************************************************************************************
Sub ProcessRecord_S(sFile As String)
Dim iFreeFile As Integer
Dim vMarc As Variant
Dim lRTPos As Long
Dim sMarcRecord As String
Dim dbMarc As Database
Set dbMarc = OpenDatabase("D:\Marc21\marc21.mdb")
'Made these recordsets modular because I step into two functions saving the information.
'In addition, the text file could hold thousands of records (that's a lot of loops).
Set mrsLeaders = dbMarc.OpenRecordset("Select * From NewLeaders")
Set mrsTags = dbMarc.OpenRecordset("Select * From NewTags")
Set mrsFields = dbMarc.OpenRecordset("Select * From NewFields")
lRTPos = 0 'Initialize
iFreeFile = FreeFile 'Get an available Free file number
Open sFile For Input As #iFreeFile 'Open the text file.
vMarc = Input$(LOF(iFreeFile), iFreeFile) 'Not sure what the limit is, but I have
Close #iFreeFile 'tested data as big as 10 megs.
Do Until vMarc = "" 'Going to loop till the variant is turned into an empty string
lRTPos = InStr(vMarc, Marc21_RecordTerminator) 'Since there can be more than one MarcRecord, we will use the position of the
'Record Terminator (RT) to determine where the Marc Record ends
sMarcRecord = Left(vMarc, lRTPos - 1) 'Record minus RT
If Not SaveRecord_F(sMarcRecord) Then
MsgBox "Saving Marc Record Failed"
Exit Sub
End If
vMarc = Mid(vMarc, lRTPos + 1)
Loop
End Sub
'***********************************************************************************************************************
' PROCEDURE: SaveRecord_F
'
' PURPOSE: Saves tags and indicators (if applicable) to the Tag table
'
'PARAMETERS: sMarcRecord -- Marc Record passed (this string can be up to 99,999 characters long)
'
'
' Date: Name: Description:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 03/06/01 Ray Initial Creation
'***********************************************************************************************************************
Function SaveRecord_F(sMarcRecord As String)
Dim sLeader As String * 24
Dim sDirectory As String 'Whole Directory
Dim sVarFields As String 'All Control and Data Fields
Dim lDirectoryEnd As Long 'Position where Directory ends
Dim lDataEntries As Long 'Determines number of Field Entries
Dim lFieldLength As Long
Dim lStartingPosition As Long
Dim lLeaderID As Long
Dim lTagID As Long
Dim sField As String
Dim sDirectoryEntry() As String
Dim bControl As Boolean
Dim lCurDirEntry As Long
Const Marc21_FLP = 4 'Field Length position relative to directory
sLeader = Left(sMarcRecord, Marc21_LdrLength) 'Set Leader
lDirectoryEnd = InStr(Marc21_LdrLength + 1, sMarcRecord, Marc21_FieldTerminator) - Marc21_FieldTerminatorPos 'Set position for end of Directory (excluding FT)
sDirectory = Mid(sMarcRecord, Marc21_LdrLength + 1, lDirectoryEnd - Marc21_LdrLength) 'Set Directory minus field terminator
'Set Variable Fields by taking end of directory position, adding one
'for the FT position and then adding another "1" to mark the beginning of the
'vfields
sVarFields = Mid(sMarcRecord, lDirectoryEnd + Marc21_FieldTerminatorPos + 1)
lDataEntries = Len(sDirectory) 'Get Length of Directory
'Make sure Directory Length Matches with Marc21 Records
If lDataEntries Mod Marc21_DirLength <> 0 Then
MsgBox "Directory Entries are messed up"
Exit Function
End If
'Add Leader to Leader Table
mrsLeaders.AddNew
lLeaderID = mrsLeaders!LeaderID 'Need this newly assigned ID to process info below
mrsLeaders!leader = sLeader
mrsLeaders.Update
'Get Number of Directory Entries for this Marc Record
lDataEntries = lDataEntries / Marc21_DirLength
'Store Tag information and, while still looping, store Variable Field Info pertaining
'to TagID pertaining to Leader
For lCurDirEntry = 0 To lDataEntries - 1
'Starting Position of Field Entry
lStartingPosition = Val(Mid(sDirectory, lCurDirEntry * Marc21_DirLength + Marc21_DirStartingPos + Marc21_PositionAdjustment, Marc21_DirStartingPosLength))
'Field length in directory relative to current record
lFieldLength = Val(Mid(sDirectory, (lCurDirEntry * Marc21_DirLength) + Marc21_DirLengthOfFieldPos + Marc21_FieldTerminatorPos, Marc21_DirLengthOfFieldLength))
mrsTags.AddNew
mrsTags!LeaderID = lLeaderID
'According to MARC, the tag within a directory starts at position zero, so we adjust it by one for the MID function
mrsTags!Tag = Mid(sDirectory, lCurDirEntry * Marc21_DirLength + Marc21_PositionAdjustment, Marc21_DirTagLength)
'Set indicators for Data Fields (non-control fields)
If Val(mrsTags!Tag) > Marc21_MaxControlFieldTagValue Then
mrsTags!Indicator1 = Mid(sVarFields, lStartingPosition + 1, Marc21_IndicatorLength)
mrsTags!Indicator2 = Mid(sVarFields, lStartingPosition + 2, Marc21_IndicatorLength)
lStartingPosition = lStartingPosition + Marc21_MovePastIndicators
lFieldLength = lFieldLength - Marc21_MovePastIndicators 'Adjust field length accordingly
bControl = False
Else
lStartingPosition = lStartingPosition + Marc21_PositionAdjustment 'Adjusted b/c Marc21's defines positions of fields based on position zero. VB uses base 1. Imagine that.
bControl = True
End If
lTagID = mrsTags!TagID
'mrsTags!FieldDesc = Mid(sVarFields, lStartingPosition + 1, lFieldLength - 1) 'Directory Entry - Field Termintor (FT)
mrsTags.Update
'Only Get field pertaining to Direcotry Entry Just Saved
sField = Mid(sVarFields, lStartingPosition, lFieldLength)
SaveFields_F sField, lTagID, bControl 'Adding and Subtracting two is accounting for indicators
Next lCurDirEntry
SaveRecord_F = True
End Function
'***********************************************************************************************************************
' PROCEDURE: SaveFields_F
'
' PURPOSE: Saves the variable data and control fields to its respective table
'
'PARAMETERS: sField -- The data which must be filtered
' lTagID -- The unique identifier related to the records about to be stored
' bControl -- Optional. Let's sub know if data is a control field or not
'
'
' Date: Name: Description:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 03/06/01 Ray Initial Creation
'***********************************************************************************************************************
Function SaveFields_F(sField As String, lTagID As Long, Optional bControl As Boolean)
Dim lDelimeterPos As Long
If Not bControl Then 'Not a control Field
If Left(sField, 1) = Marc21_Delimiter Then
sField = Mid(sField, 2) 'Move past delimeter
Else
'All non-control fields should start with delimeters
MsgBox "This entry didn't start out with a delimeter", vbOKOnly, "Uh Oh"
Exit Function
End If
lDelimeterPos = InStr(1, sField, Marc21_Delimiter)
Do Until lDelimeterPos = 0
'Store new subfield code and field description
mrsFields.AddNew
mrsFields!TagID = lTagID
mrsFields!SubFieldCode = Left(sField, 1)
mrsFields!FieldDesc = Mid(sField, Marc21_MovePastSubfieldCode, lDelimeterPos - Marc21_MovePastSubfieldCode) 'Start at position two b/c of subfield code. Subtract by 2 b/c of where started
mrsFields.Update
sField = Mid(sField, lDelimeterPos + 1)
'Get new delimeter position
lDelimeterPos = InStr(1, sField, Marc21_Delimiter)
Loop
If sField <> "" Then
mrsFields.AddNew
mrsFields!TagID = lTagID
mrsFields!SubFieldCode = Left(sField, 1)
mrsFields!FieldDesc = Mid(sField, Marc21_MovePastSubfieldCode)
mrsFields.Update
End If
Else
If sField <> "" Then
If Right(sField, 1) = Marc21_FieldTerminator Then
sField = Mid(sField, 1, Len(sField) - Marc21_FieldTerminatorPos)
End If
mrsFields.AddNew
mrsFields!TagID = lTagID
mrsFields!FieldDesc = sField
mrsFields.Update
End If
End If
End Function
我可以找到我创建(和使用)的访问数据库here。