blob: fa6459b4cbc4cba0cd5eb1e0b2b3b0806f64cfb3 [file] [log] [blame]
Michael Hanl704211e2015-06-19 07:26:04 +02001package de.ids_mannheim.korap.resource;
2
Michael Hanlbadd79c2015-06-19 07:41:03 +02003import de.ids_mannheim.korap.config.KustvaktConfiguration;
Michael Hanl00b64e02016-05-24 20:24:27 +02004import de.ids_mannheim.korap.config.Attributes;
Michael Hanle4fc7752016-02-17 11:41:18 +01005import de.ids_mannheim.korap.user.Userdata;
Michael Hanl704211e2015-06-19 07:26:04 +02006
7/**
8 * @author hanl
9 * @date 14/10/2014
10 */
11public class LayerMapper {
12
Michael Hanle4fc7752016-02-17 11:41:18 +010013 private Userdata settings;
Michael Hanlbadd79c2015-06-19 07:41:03 +020014 private KustvaktConfiguration config;
Michael Hanl704211e2015-06-19 07:26:04 +020015
Michael Hanl8abaf9e2016-05-23 16:46:35 +020016
17 public LayerMapper (KustvaktConfiguration config, Userdata settings) {
Michael Hanl704211e2015-06-19 07:26:04 +020018 this.settings = settings;
Michael Hanl1e18cb42015-08-06 20:57:35 +020019 this.config = config;
Michael Hanlbadd79c2015-06-19 07:41:03 +020020 }
21
Michael Hanl8abaf9e2016-05-23 16:46:35 +020022
23 public LayerMapper (KustvaktConfiguration config) {
Michael Hanl1e18cb42015-08-06 20:57:35 +020024 this.config = config;
Michael Hanl704211e2015-06-19 07:26:04 +020025 }
26
Michael Hanl8abaf9e2016-05-23 16:46:35 +020027
Michael Hanl704211e2015-06-19 07:26:04 +020028 /**
Michael Hanl8abaf9e2016-05-23 16:46:35 +020029 * find foundry entry in settings specific settings. Includes a
30 * call to #translateLayer to get the
Michael Hanl704211e2015-06-19 07:26:04 +020031 * correct mapping for the layer denomination!
Michael Hanl8abaf9e2016-05-23 16:46:35 +020032 *
Michael Hanl704211e2015-06-19 07:26:04 +020033 * @param layer
34 * @return
35 */
36
37 //todo: make mapping configurable!
Michael Hanl8abaf9e2016-05-23 16:46:35 +020038 public String findFoundry (String layer) {
Michael Hanl704211e2015-06-19 07:26:04 +020039 if (settings != null) {
40 switch (translateLayer(layer.toLowerCase().trim())) {
41 case "d":
Michael Hanl25aac542016-02-01 18:16:44 +010042 return (String) settings
43 .get(Attributes.DEFAULT_REL_FOUNDRY);
Michael Hanl704211e2015-06-19 07:26:04 +020044 case "c":
Michael Hanl25aac542016-02-01 18:16:44 +010045 return (String) settings
46 .get(Attributes.DEFAULT_CONST_FOUNDRY);
Michael Hanl704211e2015-06-19 07:26:04 +020047 case "pos":
Michael Hanl25aac542016-02-01 18:16:44 +010048 return (String) settings
49 .get(Attributes.DEFAULT_POS_FOUNDRY);
Michael Hanl704211e2015-06-19 07:26:04 +020050 case "lemma":
Michael Hanl25aac542016-02-01 18:16:44 +010051 return (String) settings
52 .get(Attributes.DEFAULT_LEMMA_FOUNDRY);
Michael Hanl704211e2015-06-19 07:26:04 +020053 case "surface":
54 return "opennlp";
55 default:
56 // if the layer is not in this specific listing, assume a default layer
57 // like orth or other tokenization layers
Michael Hanlc0ed00f2016-06-23 14:33:10 +020058 return null;
Michael Hanl704211e2015-06-19 07:26:04 +020059 }
Michael Hanl8abaf9e2016-05-23 16:46:35 +020060 }
61 else {
Michael Hanl704211e2015-06-19 07:26:04 +020062 switch (translateLayer(layer.toLowerCase().trim())) {
63 case "d":
64 return config.getDefault_dep();
65 case "c":
66 return config.getDefault_const();
67 case "pos":
68 return config.getDefault_pos();
69 case "lemma":
70 return config.getDefault_lemma();
71 case "surface":
Michael Hanlf21773f2015-10-16 23:02:31 +020072 return config.getDefault_token();
Michael Hanl8abaf9e2016-05-23 16:46:35 +020073 // refers to "structure" and is used for paragraphs or sentence boundaries
Michael Hanl505f48c2015-06-26 19:04:27 +020074 case "s":
75 return "base";
Michael Hanl704211e2015-06-19 07:26:04 +020076 default:
77 // if the layer is not in this specific listing, assume a default layer
78 // like orth or other tokenization layers
Michael Hanlc0ed00f2016-06-23 14:33:10 +020079 return null;
Michael Hanl704211e2015-06-19 07:26:04 +020080 }
81 }
82 }
83
Michael Hanl8abaf9e2016-05-23 16:46:35 +020084
Michael Hanl704211e2015-06-19 07:26:04 +020085 // relevance: map to access control id references. p is usually mapped to pos, l to lemma, etc.
Michael Hanl8abaf9e2016-05-23 16:46:35 +020086 public String translateLayer (String layer) {
Michael Hanl704211e2015-06-19 07:26:04 +020087 switch (layer.toLowerCase().trim()) {
Michael Hanl8abaf9e2016-05-23 16:46:35 +020088 // case "pos":
89 // return "p";
90 // case "lemma":
91 // return "l";
Michael Hanl704211e2015-06-19 07:26:04 +020092 case "m":
93 return "msd";
Michael Hanl8abaf9e2016-05-23 16:46:35 +020094 //todo the orth layer does not need a foundry entry
Michael Hanl704211e2015-06-19 07:26:04 +020095 case "orth":
96 return "surface";
97 case "t":
98 return "surface";
99 case "const":
100 return "c";
101 case "p":
102 return "pos";
103 case "l":
104 return "lemma";
105 default:
106 return layer;
107 }
108 }
109
110}