/* eds_holdings.go - Convert Google Scholar XML to EBSCO Discovery Service holdings Copyright (C) 2012 Dan Scott This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package main import "encoding/xml" import "fmt" import "io/ioutil" type Coverage struct { FromYear int `xml:"from>year"` FromVolume int `xml:"from>volume"` FromIssue string `xml:"from>issue"` ToYear int `xml:"to>year"` ToVolume int `xml:"to>volume"` ToIssue string `xml:"to>issue"` } type Result struct { XMLName xml.Name `xml:"item"` Id int `xml:"sfx_id"` Type string `xml:"object_type"` Titles []string `xml:"title"` ISSN string `xml:"issn"` EISSN string `xml:"eissn"` Coverages []Coverage `xml:"coverage"` } type Holding struct { XMLName xml.Name `xml:"institutional_holdings"` Results []Result `xml:"item"` } func getCoverageYears(covers []Coverage) (fromY int, toY int) { fromY = 9999 toY = -1 current := 0 for _, cover := range covers { if cover.FromYear < fromY { fromY = cover.FromYear } if cover.ToYear == 0 { current = 1 } if cover.ToYear > toY { toY = cover.ToYear } } if fromY == 9999 { fromY = -1 } /* A current subscription overrides everything */ if current == 1 { toY = -1 } return fromY, toY } func main() { v := Holding{} /* data := ` 954921332001 JOURNAL Publishers weekly 0000-0019 2150-4008 1997 1997 1995 48 1990 1990 1990 2000 954921332003 JOURNAL Communications of the ACM ASSOCIATION FOR COMPUTING MACHINERY COMMUNICATIONS OF THE ACM COMMUNICATIONS OF THE ASSOCIATION FOR COMPUTING MACHINERY ASSOCIATION FOR COMPUTING MACHINERY COMMUNICATIONS 0001-0782 1557-7317 1958 1 1 1999 1987 2001 1987 2001 1958 1 1 2011 54 9 954921332004 JOURNAL Planning Planning (U.S.) Planning (U.K.) 0001-2610 0001-2510 1993 1993 1987 954921333005 JOURNAL Abacus ABACUS A JOURNAL OF ACCOUNTING FINANCE AND BUSINESS STUDIES ABACUS OXFORD 0001-3072 1467-6281 1997 33 1 1965 365 1997 33 1 2012 48 1 1965 1 1 1997 ` */ file, err := ioutil.ReadFile("institutional_holding-laurentian.xml") err = xml.Unmarshal(file, &v) if err != nil { fmt.Printf("error: %v", err) return } for _, result := range v.Results { /* EBSCO says an ISSN is necessary, but this wipes out 56,000 results */ if result.EISSN == "" && result.ISSN == "" { break } fmt.Printf("%s\t", result.Titles[0]) if result.EISSN != "" { fmt.Printf("%s\t", result.EISSN) } else { fmt.Printf("%s\t", result.ISSN) } fromY, toY := getCoverageYears(result.Coverages) if fromY > 0 { fmt.Printf("%04d\t", fromY) } else { fmt.Printf("\t") } if toY > 0 { fmt.Printf("%04d\n", toY) } else { fmt.Printf("\n") } } }