RE: [solrmarc-tech] field separator question

30 views
Skip to first unread message

Demian Katz

unread,
Oct 4, 2012, 9:18:24 AM10/4/12
to solrma...@googlegroups.com

This definitely sounds like a task for a .bsh script; I’m pretty sure there’s not a built-in function that will allow you to mix and match separators.

 

I don’t know the Marc4j syntax off the top of my head, but here’s a pseudocode representation of what you could do:

 

field = record.getField(600);

string = “”;

foreach (field.getSubfields as subfield) {

    if (subfield.getCode() == ‘d’ && string.length > 0) {

        string += “ “;

    } else if (string.length > 0) {

        string += “--";

    }

    string += subfield.getText();

}

return string;

 

I’m pretty sure that all of the operations in that pseudocode are possible (and straightforward) in a .bsh script if you just look up the syntax.

 

- Demian

 

From: solrma...@googlegroups.com [mailto:solrma...@googlegroups.com] On Behalf Of Adam Wead
Sent: Wednesday, October 03, 2012 5:19 PM
To: solrma...@googlegroups.com
Subject: [solrmarc-tech] field separator question

 

Hi all,

 

I have a 600 field like this:

  a| Lennon, John, d| 1940-1980 x| Assassination

 

And want subfields a and d to be joined with a space but any subsequent subfields joined with a "--" to look like this:

  Lennon, John, 1940-1980--Assassination

 

I've got some .bsh scripts already doing some customization, but I can't seem to figure out how to solve this particular problem.  If anyone can point me to some code sample or documentation that might show how to tackle this particular problem, I'd be very grateful!

 

Many thanks,

 

...adam

Adam Wead | Systems and Digital Collections Librarian

ROCK AND ROLL HALL OF FAME + MUSEUM 

Library and Archives

--
You received this message because you are subscribed to the Google Groups "solrmarc-tech" group.
To view this discussion on the web visit https://groups.google.com/d/msg/solrmarc-tech/-/eyxHRxcXnysJ.
To post to this group, send email to solrma...@googlegroups.com.
To unsubscribe from this group, send email to solrmarc-tec...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/solrmarc-tech?hl=en.

Demian Katz

unread,
Oct 5, 2012, 10:41:39 AM10/5/12
to solrma...@googlegroups.com
Custom methods in SolrMarc get passed a Marc4j Record object.

You can get values for a particular field out of the Record object like this:

        List<DataField> fields = record.getVariableFields("600");
        Iterator<DataField> fieldsIter = fields.iterator();
        if (fields != null) {
            DataField currentField;
            while(fieldsIter.hasNext()) {
                currentField = (ControlField) fieldsIter.next();
            }
        }

(Note that this is "true" Java code.  If you are doing this in Beanshell you may need to remove the <DataField> template specifications from some of the types in the above example due to minor typing differences).

Once you have a field object, you can extract subfields like this:

        List<Subfield> subfields = currentField.getFieldList();
        Iterator<Subfield> subfieldsIter = subfields.iterator();
        if (subfields != null) {
            Subfield currentSubfield;
            while (subfieldsIter.hasNext()) {
                currentSubfield = (Subfeld) subfieldsIter.next();
            }
        }

(Same thing with <Subfield> as noted above for <DataField>)

Now you have access to a currentSubfield object that can be processed accordingly.

- Demian


From: solrma...@googlegroups.com [solrma...@googlegroups.com] on behalf of Adam Wead [amste...@gmail.com]
Sent: Friday, October 05, 2012 9:47 AM
To: solrma...@googlegroups.com
Subject: [solrmarc-tech] Re: field separator question

Demian,

Thanks for this.  That makes complete sense.  However, after digging around in the SolrMarc code and marc4j source code, I'm seeing methods in SolrMarc that return only strings of the subfields, without the subfield indicators.  For example, getAllSubfields returns a set of strings, one for each subfield.  marc4j has the getCode and getData methods which I think would extract the subfield code and the content of the subfield, respectively, but I'm confused as to which methods to use from which library, and what I should iterate over in order to get both subfield indicator and field content.  I guess what I need is some kind of hash:

"a" = "subfield a content",
"b" = "subfield b content"

Java is not my forte, so if I'm missing something obvious, I apologize in advance!

best,

...adam

--
You received this message because you are subscribed to the Google Groups "solrmarc-tech" group.
To view this discussion on the web visit https://groups.google.com/d/msg/solrmarc-tech/-/utc-2gp3VQcJ.

Naomi Dushay

unread,
Oct 5, 2012, 1:31:32 PM10/5/12
to solrma...@googlegroups.com
Demian,

If this isn't up on the wikis, it probably should be ..

- Naomi

Demian Katz

unread,
Oct 5, 2012, 2:29:00 PM10/5/12
to solrma...@googlegroups.com
I guess the real question is where it belongs -- I don't think it makes sense for us to duplicate the Marc4j documentation in the SolrMarc documentation (and most of these details are really Marc4j-specific...  the only SolrMarc detail is the fact that custom methods get a Record object passed in, which I'm sure the wiki already covers).  The tricky thing is, though, that when I tried to look this up in the Marc4j docs, they were really incomplete and didn't mention all the methods.  Maybe I was looking in the wrong place... but if not, I think this should be addressed on the Marc4j side, and then the SolrMarc docs can link to the Marc4j docs for specifics.

- Demian

From: solrma...@googlegroups.com [solrma...@googlegroups.com] on behalf of Naomi Dushay [ndu...@stanford.edu]
Sent: Friday, October 05, 2012 1:31 PM
To: solrma...@googlegroups.com
Subject: Re: [solrmarc-tech] field separator question

Reply all
Reply to author
Forward
0 new messages