├── .gitignore
├── LICENSE
├── NOTICE
├── README.md
├── build.sh
├── build.xml
├── configs
├── README
├── example.csv
├── feed.sh
├── restart-solr-dbg.sh
├── restart-solr.sh
└── solr
│ ├── core0
│ ├── conf
│ │ ├── schema.xml
│ │ └── solrconfig.xml
│ └── core.properties
│ ├── knowledge-graph
│ ├── conf
│ │ ├── mapping-FoldToASCII.txt
│ │ ├── mapping-ISOLatin1Accent.txt
│ │ ├── schema.xml
│ │ └── solrconfig.xml
│ └── core.properties
│ └── solr.xml
├── knowledge-graph
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── careerbuilder
│ │ └── search
│ │ └── relevancy
│ │ ├── FieldChecker.java
│ │ ├── KnowledgeGraphHandler.java
│ │ ├── NodeContext.java
│ │ ├── RecursionOp.java
│ │ ├── RequestTreeRecurser.java
│ │ ├── RequestValidator.java
│ │ ├── generation
│ │ ├── FacetFieldAdapter.java
│ │ └── NodeGenerator.java
│ │ ├── model
│ │ ├── Error.java
│ │ ├── KnowledgeGraphRequest.java
│ │ ├── KnowledgeGraphResponse.java
│ │ ├── ParameterSet.java
│ │ ├── RequestNode.java
│ │ ├── ResponseNode.java
│ │ ├── ResponseValue.java
│ │ └── SortType.java
│ │ ├── normalization
│ │ └── NodeNormalizer.java
│ │ ├── responsewriter
│ │ ├── KnowledgeGraphResponseWriter.java
│ │ └── ResponseValueSerializer.java
│ │ ├── scoring
│ │ ├── BackupScorer.java
│ │ ├── BinomialStrategy.java
│ │ ├── NodeScorer.java
│ │ ├── QueryRunnerFactory.java
│ │ └── ScoreNormalizer.java
│ │ ├── threadpool
│ │ ├── ThreadPool.java
│ │ └── ThreadPoolHolder.java
│ │ ├── utility
│ │ ├── MapUtility.java
│ │ ├── ParseUtility.java
│ │ ├── ResponseUtility.java
│ │ └── SortUtility.java
│ │ └── waitable
│ │ ├── AggregationWaitable.java
│ │ ├── QueryWaitable.java
│ │ └── Waitable.java
│ └── test
│ └── java
│ └── com
│ └── careerbuilder
│ └── search
│ └── relevancy
│ ├── Model
│ ├── ResponseNodeTest.java
│ └── ResponseValueTest.java
│ ├── RequestTreeRecurserTest.java
│ ├── RequestValidatorTest.java
│ ├── generation
│ ├── FacetFieldAdapterTest.java
│ └── NodeGeneratorTest.java
│ ├── normalization
│ └── NodeNormalizerTest.java
│ ├── responsewriter
│ ├── KnowledgeGraphResponseWriterTest.java
│ └── ResponseValueSerializerTest.java
│ ├── scoring
│ ├── BackupScorerTest.java
│ ├── NodeScorerTest.java
│ ├── QueryWaitableFactoryTest.java
│ ├── RelatednessStrategyTest.java
│ └── ScoreNormalizerTest.java
│ ├── threadpool
│ ├── MapUtilityTest.java
│ └── ThreadPoolTest.java
│ ├── utility
│ └── ResponseUtilityTest.java
│ └── waitable
│ ├── AggregationWaitableTest.java
│ └── QueryWaitableTest.java
├── patches
└── lucene_solr_5_1_0.patch
└── rebuild.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | deploy
2 | lucene-solr
3 | cores/
4 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
5 |
6 | *.iml
7 |
8 | ## Directory-based project format:
9 | .idea/
10 | # if you remove the above rule, at least ignore the following:
11 |
12 | # User-specific stuff:
13 | # .idea/workspace.xml
14 | # .idea/tasks.xml
15 | # .idea/dictionaries
16 |
17 | # Sensitive or high-churn files:
18 | # .idea/dataSources.ids
19 | # .idea/dataSources.xml
20 | # .idea/sqlDataSources.xml
21 | # .idea/dynamic.xml
22 | # .idea/uiDesigner.xml
23 |
24 | # Gradle:
25 | # .idea/gradle.xml
26 | # .idea/libraries
27 |
28 | # Mongo Explorer plugin:
29 | # .idea/mongoSettings.xml
30 |
31 | ## File-based project format:
32 | *.ipr
33 | *.iws
34 |
35 | ## Plugin-specific files:
36 |
37 | # IntelliJ
38 | /out/
39 |
40 | # mpeltonen/sbt-idea plugin
41 | .idea_modules/
42 |
43 | # JIRA plugin
44 | atlassian-ide-plugin.xml
45 |
46 | # Crashlytics plugin (for Android Studio and IntelliJ)
47 | com_crashlytics_export_strings.xml
48 | crashlytics.properties
49 | crashlytics-build.properties
50 |
51 | #Maven
52 | target/
53 | pom.xml.tag
54 | pom.xml.releaseBackup
55 | pom.xml.versionsBackup
56 | pom.xml.next
57 | release.properties
58 | dependency-reduced-pom.xml
59 | buildNumber.properties
60 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2016 Careerbuilder LLC
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Semantic Knowledge Graph
2 | Copyright 2016 CareerBuilder, LLC
3 | This product includes software developed at CareerBuilder, LLC (http://www.careerbuilder.com)
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #Semantic Knowledge Graph
2 | *A graph structure, build automatically from a corpus of data, for traversing and measuring relationships within a domain*
3 |
4 | The Semantic Knowledge Graph serves as a data scientist's toolkit, allowing you to discover and compare any entities modeled within a corpus of data from any domain. For example, if you indexed a corpus of job postings, you could figure out what the most related job titles are for the phrase "account manager", and subsequently what the top skills are for each of those job titles. You can also use the system to rank a list of entities or keywords based upon their statistical relationship with any other group of entities or terms, and you can traverse these relationships any number of levels deep. The Semantic Knowledge Graph will allow you to slice and dice the universe of terms and entites represented within your corpus in order to discover as many of these insights as you have the time and curiosity to pursue.
5 |
6 | The Semantic Knowledge Graph is packaged as a request handler plugin for the popular Apache Solr search engine. Fundamentally, you must create a schema representing your corpus of data (from any domain), send the corpus of documents to Solr (script to do this is included), and then you can send queries to the Semantic Knowledge Graph request handler to discover and/or score relationships.
7 |
8 | ## License and Citation
9 |
10 | The Semantic Knowledge Graph source code is licensed under the [ASL 2.0 License](https://github.com/careerbuilder/semantic-knowledge-graph/blob/master/LICENSE).
11 |
12 | A research paper describing the Semantic Knowledge Graph is being published in the proceedings of the 2016 IEEE 3rd International Conference on Data Science and Advanced Analytics:
13 |
14 | [The Semantic Knowledge Graph: A compact, auto-generated model for real-time traversal and ranking of any relationship within a domain](https://arxiv.org/abs/1609.00464).
15 |
16 | Please cite the Semantic Knowledge Graph in your publications if it helps your research:
17 |
18 | @article{grainger2016SemanticKnowledgeGraph,
19 | Author = {Grainger, Trey and AlJadda, Khalifeh and Korayem, Mohammed and Smith, Andries},
20 | Journal = {arXiv preprint arXiv:1609.00464},
21 | Title = {The Semantic Knowledge Graph: A compact, auto-generated model for real-time traversal and ranking of any relationship within a domain},
22 | Year = {2016}
23 | }
24 |
25 | #Usage (examples from the job search domain):
26 |
27 | *Request:*
28 | ```
29 | curl -X POST http://localhost:8983/solr/skg/rel \
30 | -H "Content-Type: application/json" \
31 | -d \
32 | '{
33 | "queries": [
34 | "keywords:\"data scientist\""
35 | ],
36 | "compare": [
37 | {
38 | "type": "jobtitle",
39 | "limit": 1,
40 | "compare": [
41 | {
42 | "type": "skills",
43 | "limit": 5,
44 | "discover_values": true,
45 | "values": [
46 | "java (programming language)"
47 | ]
48 | }
49 | ]
50 | }
51 | ]
52 | }'
53 | ```
54 |
55 | Response:
56 | ```
57 | { "data": [
58 | {
59 | "type": "jobtitle",
60 | "values": [
61 | {
62 | "id": "",
63 | "name": "Data Scientist",
64 | "relatedness": 0.989,
65 | "popularity": 86.0,
66 | "foreground_popularity": 86.0,
67 | "background_popularity": 142.0,
68 | "compare": [
69 | {
70 | "type": "skills.v3",
71 | "values": [
72 | {
73 | "id": "",
74 | "name": "Machine Learning",
75 | "relatedness": 0.97286,
76 | "popularity": 54.0,
77 | "foreground_popularity": 54.0,
78 | "background_popularity": 356.0
79 | },
80 | {
81 | "id": "",
82 | "name": "Predictive Modelling",
83 | "relatedness": 0.94565,
84 | "popularity": 27.0,
85 | "foreground_popularity": 27.0,
86 | "background_popularity": 384.0
87 | },
88 | {
89 | "id": "",
90 | "name": "Artificial Neural Networks",
91 | "relatedness": 0.94416,
92 | "popularity": 10.0,
93 | "foreground_popularity": 10.0,
94 | "background_popularity": 57.0
95 | },
96 | {
97 | "id": "",
98 | "name": "Apache Hadoop",
99 | "relatedness": 0.94274,
100 | "popularity": 50.0,
101 | "foreground_popularity": 50.0,
102 | "background_popularity": 1418.0
103 | },
104 | {
105 | "id": "",
106 | "name": "Java (Programming Language)",
107 | "relatedness": 0.76606,
108 | "popularity": 37.0,
109 | "foreground_popularity": 37.0,
110 | "background_popularity": 17442.0
111 | }
112 | ]
113 | }
114 | ]
115 | }
116 | ]
117 | }
118 | ]
119 | }
120 | ```
121 |
122 | #Available Request Options
123 | **queries** String[]
124 | A set of Solr queries which will be used to generate entities for scoring. If no foreground queries are supplied, these queries will also be used to score the entities. Multiple queries are merged to find the intersection between them (equivalent of a boolean AND query). See the types parameter for query field types.
125 |
126 | Note: the default operator between keywords is OR. If you wish to search for multiple words as a phrase, wrap them in quotes. If you want to make all keywords required, add a + before them or insert an AND between them:
127 | senior java developer = senior OR java OR developer
128 | +senior +java +developer = senior AND java AND developer
129 | "senior java developer" = Exact phrase match for all three words in order
130 | "senior" "java developer" = senior OR "java developer"
131 |
132 | **compare** Object[]
133 | An arbitrarily nested (recursive) list of objects corresponding to entity types to generate and score. Each item in the comparison list will generate scored lists of values based upon the requested relationship to their containing parent.
134 |
135 | **type** String
136 | The type of entity to generate or score. These types correspond to the fields in your Solr schema.xml
137 |
138 | **sort** optional String
139 | The field to sort on. Supported fields include:
140 | relatedness (statistical correlation)
141 | popularity (count per 1 million documents)
142 | foreground_popularity (popularity within the foreground query)
143 | background_popularity (popularity within the background query)
144 |
145 | Defaults to relatedness.
146 |
147 | **limit** optional integer
148 | The limit on the result set size. Defaults to 1.
149 |
150 | **values** optional String[]
151 | A set of values to score. Only exact id or name matches are will be scored correctly. Note: unless passed-in values do not meet the minimum popularity requirement, passed-in values override generated values in the result set. For example, if three values are passed in and a limit of ten is set, the top seven generated values will be returned along with the three passed-in values, regardless of scores or popularity of the passed-in values.
152 |
153 | **discover_values** optional boolean
154 | Whether or not to generate values. If set to true, the query in the queries parameter will be used to automatically generate a set of values to score. Defaults to "true" if no values are passed in in the values parameter, "false" otherwise.
155 |
156 | **compare** optional Object[]
157 | A list of nested request objects. For each value returned for this entity type, all nested request object entity types will be generated and scored. Note: the "queries" and "foreground_queries" parameters are combined with the parent entity value when generating / scoring nested entities.
158 |
159 | **foreground_queries** optional String[]
160 | If supplied, a set of Solr queries used to score the results generated using the queries in the queries parameter. The relatedness score will measure statistical skewedness toward the foreground_queries queries merged together using AND. Defaults to the value of the queries parameter. See the types parameter for query field types.
161 |
162 | **background_queries** optional String[]
163 | If supplied, a set of Solr queries used to score the results generated using the queries in the queries parameter. The relatedness score will measure statistical skewedness away from the background_queries queries merged together using AND. Defaults to match all documents. See the types parameter for query field types.
164 |
165 | **min_popularity** optional double
166 | The minimum popularity of returned results (assuming exactly 1 million total documents). Results which have a popularity, foreground popularity, or background popularity lower than min_popularity out of 1 million are omitted. Defaults to at least 1 hit per million documents.
167 |
168 | **normalize_values** optional boolean
169 | Whether the API should attempt to find ids and names for passed-in values. If false, the API will return passed-in values in the name field without regard to whether they represent an id or name for an entity. Turning normalization off may boost performance. Defaults to "true."
170 |
171 | #Building and Running
172 | The easiest way to build the Semantic Knowledg Graph is to run the `build.sh` script in the root directory of the project (or `rebuild.sh`, which will build and launch an Apache Solr instance with the Semantic Knowledge Graph configured). The final application will be found in the `deploy` directory, and you can launch it using the `restart-solr.sh` script found in that directory. You can simply copy this `deploy` folder to your production environment and run the `restart-solr.sh` script to launch the service. By default, you can hit it at `http://localhost:8983/solr/knowledge-graph/rel`. See the example in the Examples section above for usage.
173 |
174 | #Using the System
175 | Once the Semantic Knowledge Graph project has been built, you need to indexing a corpus of data through it by running the `feed.sh` script. The fields you include in your corpus should correspond to the fields defined in your Solr `schema.xml` found in the `deploy/solr/knowledge-graph/conf` directory.
176 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | ant pull
2 | cd lucene-solr
3 | ant ivy-bootstrap
4 | cd ../knowledge-graph/
5 | mvn clean
6 | mvn package
7 | cd ../
8 | ant package
9 | cd deploy
10 | chmod +x restart-solr.sh
11 | chmod +x restart-solr-dbg.sh
12 | chmod +x feed.sh
13 | chmod +x solr/bin/solr
14 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
--------------------------------------------------------------------------------
/configs/README:
--------------------------------------------------------------------------------
1 | To feed the example, run "./feed.sh ./ knowledge-graph" in this directory.
2 |
3 | Example query:
4 | {"queries":["field.v1:\"data scientist\""],"min_popularity":0.0,"compare":[{"type":"field.v1","limit":5, "sort":"relatedness"}]}
5 |
--------------------------------------------------------------------------------
/configs/example.csv:
--------------------------------------------------------------------------------
1 | id,content,field.v1,field.v1.id-name
2 | 1,This is an example,1|data scientist,1^data scientist
3 | 2,data analytics,2|data analytics|1|data scientist,2^data analytics|1^data scientist
4 | 3,data analytics,2|data analytics|1|data scientist,2^data analytics|1^data scientist
5 | 4,data analytics,2|data analytics|1|data scientist,2^data analytics|1^data scientist
6 | 5,data analytics,2|data analytics|1|data scientist,2^data analytics|1^data scientist
7 | 6,something else,3|machine learning,3^machine learning
8 | 7,something else,3|machine learning,3^machine learning
9 | 8,something else,3|machine learning,3^machine learning
10 | 9,something else,3|machine learning,3^machine learning
11 | 10,something else,3|machine learning,3^machine learning
12 |
--------------------------------------------------------------------------------
/configs/feed.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | CSVFOLDER=$1
3 | CORENAME=$2
4 |
5 | for file in $CSVFOLDER/*.csv
6 | do
7 | curl http://localhost:8983/solr/$CORENAME/update?commit=true --data-binary @$file -H 'Content-type:text/csv'
8 | done
9 |
10 |
--------------------------------------------------------------------------------
/configs/restart-solr-dbg.sh:
--------------------------------------------------------------------------------
1 | solr/bin/solr restart -m 5g -a "-server -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8984"
2 |
--------------------------------------------------------------------------------
/configs/restart-solr.sh:
--------------------------------------------------------------------------------
1 | solr/bin/solr restart -m 5g -a "-server"
2 |
--------------------------------------------------------------------------------
/configs/solr/core0/conf/schema.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | id
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/configs/solr/core0/conf/solrconfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.7
4 | ${solr.data.dir:}
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | false
15 | 1
16 |
17 |
18 |
19 |
20 |
21 |
22 | solrpingquery
23 |
24 |
25 | all
26 |
27 | server-enabled
28 |
29 |
30 |
33 |
34 |
37 |
38 |
40 |
41 |
42 |
45 |
46 | explicit
47 | text
48 |
49 |
50 |
51 |
52 | *:*
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/configs/solr/core0/core.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/careerbuilder/semantic-knowledge-graph/047be46655df96ff4b6e1c790436686a60f494f6/configs/solr/core0/core.properties
--------------------------------------------------------------------------------
/configs/solr/knowledge-graph/conf/mapping-ISOLatin1Accent.txt:
--------------------------------------------------------------------------------
1 | # The ASF licenses this file to You under the Apache License, Version 2.0
2 | # (the "License"); you may not use this file except in compliance with
3 | # the License. You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 |
13 | # Syntax:
14 | # "source" => "target"
15 | # "source".length() > 0 (source cannot be empty.)
16 | # "target".length() >= 0 (target can be empty.)
17 |
18 | # example:
19 | # "À" => "A"
20 | # "\u00C0" => "A"
21 | # "\u00C0" => "\u0041"
22 | # "ß" => "ss"
23 | # "\t" => " "
24 | # "\n" => ""
25 |
26 | # À => A
27 | "\u00C0" => "A"
28 |
29 | # Á => A
30 | "\u00C1" => "A"
31 |
32 | # Â => A
33 | "\u00C2" => "A"
34 |
35 | # Ã => A
36 | "\u00C3" => "A"
37 |
38 | # Ä => A
39 | "\u00C4" => "A"
40 |
41 | # Å => A
42 | "\u00C5" => "A"
43 |
44 | # Æ => AE
45 | "\u00C6" => "AE"
46 |
47 | # Ç => C
48 | "\u00C7" => "C"
49 |
50 | # È => E
51 | "\u00C8" => "E"
52 |
53 | # É => E
54 | "\u00C9" => "E"
55 |
56 | # Ê => E
57 | "\u00CA" => "E"
58 |
59 | # Ë => E
60 | "\u00CB" => "E"
61 |
62 | # Ì => I
63 | "\u00CC" => "I"
64 |
65 | # Í => I
66 | "\u00CD" => "I"
67 |
68 | # Î => I
69 | "\u00CE" => "I"
70 |
71 | # Ï => I
72 | "\u00CF" => "I"
73 |
74 | # IJ => IJ
75 | "\u0132" => "IJ"
76 |
77 | # Ð => D
78 | "\u00D0" => "D"
79 |
80 | # Ñ => N
81 | "\u00D1" => "N"
82 |
83 | # Ò => O
84 | "\u00D2" => "O"
85 |
86 | # Ó => O
87 | "\u00D3" => "O"
88 |
89 | # Ô => O
90 | "\u00D4" => "O"
91 |
92 | # Õ => O
93 | "\u00D5" => "O"
94 |
95 | # Ö => O
96 | "\u00D6" => "O"
97 |
98 | # Ø => O
99 | "\u00D8" => "O"
100 |
101 | # Œ => OE
102 | "\u0152" => "OE"
103 |
104 | # Þ
105 | "\u00DE" => "TH"
106 |
107 | # Ù => U
108 | "\u00D9" => "U"
109 |
110 | # Ú => U
111 | "\u00DA" => "U"
112 |
113 | # Û => U
114 | "\u00DB" => "U"
115 |
116 | # Ü => U
117 | "\u00DC" => "U"
118 |
119 | # Ý => Y
120 | "\u00DD" => "Y"
121 |
122 | # Ÿ => Y
123 | "\u0178" => "Y"
124 |
125 | # à => a
126 | "\u00E0" => "a"
127 |
128 | # á => a
129 | "\u00E1" => "a"
130 |
131 | # â => a
132 | "\u00E2" => "a"
133 |
134 | # ã => a
135 | "\u00E3" => "a"
136 |
137 | # ä => a
138 | "\u00E4" => "a"
139 |
140 | # å => a
141 | "\u00E5" => "a"
142 |
143 | # æ => ae
144 | "\u00E6" => "ae"
145 |
146 | # ç => c
147 | "\u00E7" => "c"
148 |
149 | # è => e
150 | "\u00E8" => "e"
151 |
152 | # é => e
153 | "\u00E9" => "e"
154 |
155 | # ê => e
156 | "\u00EA" => "e"
157 |
158 | # ë => e
159 | "\u00EB" => "e"
160 |
161 | # ì => i
162 | "\u00EC" => "i"
163 |
164 | # í => i
165 | "\u00ED" => "i"
166 |
167 | # î => i
168 | "\u00EE" => "i"
169 |
170 | # ï => i
171 | "\u00EF" => "i"
172 |
173 | # ij => ij
174 | "\u0133" => "ij"
175 |
176 | # ð => d
177 | "\u00F0" => "d"
178 |
179 | # ñ => n
180 | "\u00F1" => "n"
181 |
182 | # ò => o
183 | "\u00F2" => "o"
184 |
185 | # ó => o
186 | "\u00F3" => "o"
187 |
188 | # ô => o
189 | "\u00F4" => "o"
190 |
191 | # õ => o
192 | "\u00F5" => "o"
193 |
194 | # ö => o
195 | "\u00F6" => "o"
196 |
197 | # ø => o
198 | "\u00F8" => "o"
199 |
200 | # œ => oe
201 | "\u0153" => "oe"
202 |
203 | # ß => ss
204 | "\u00DF" => "ss"
205 |
206 | # þ => th
207 | "\u00FE" => "th"
208 |
209 | # ù => u
210 | "\u00F9" => "u"
211 |
212 | # ú => u
213 | "\u00FA" => "u"
214 |
215 | # û => u
216 | "\u00FB" => "u"
217 |
218 | # ü => u
219 | "\u00FC" => "u"
220 |
221 | # ý => y
222 | "\u00FD" => "y"
223 |
224 | # ÿ => y
225 | "\u00FF" => "y"
226 |
227 | # ff => ff
228 | "\uFB00" => "ff"
229 |
230 | # fi => fi
231 | "\uFB01" => "fi"
232 |
233 | # fl => fl
234 | "\uFB02" => "fl"
235 |
236 | # ffi => ffi
237 | "\uFB03" => "ffi"
238 |
239 | # ffl => ffl
240 | "\uFB04" => "ffl"
241 |
242 | # ſt => ft
243 | "\uFB05" => "ft"
244 |
245 | # st => st
246 | "\uFB06" => "st"
247 |
--------------------------------------------------------------------------------
/configs/solr/knowledge-graph/conf/schema.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | id
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/configs/solr/knowledge-graph/conf/solrconfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 5.10
4 |
5 | ../../../cores/skg/data
6 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | 100000
16 |
17 |
18 |
19 | ${solr.ulog.dir:}
20 |
21 |
22 |
23 |
24 | false
25 | 2
26 |
27 |
28 |
29 |
30 |
31 | explicit
32 | true
33 | 10
34 | text
35 | AND
36 | json
37 | true
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | content
46 | edismax
47 |
48 |
49 |
51 | content
52 | skg
53 |
54 | id-name
55 |
57 | id
58 |
59 |
60 |
61 |
62 |
63 | true
64 | "
65 | |
66 | true
67 | "
68 | |
69 |
70 |
71 |
72 |
73 |
76 |
77 |
80 |
81 |
83 |
84 |
85 |
86 |
87 | solrpingquery
88 |
89 |
90 | all
91 |
92 | server-enabled
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 | true
106 | false
107 |
108 |
109 | terms
110 |
111 |
112 |
113 |
114 |
115 | *:*
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/configs/solr/knowledge-graph/core.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/careerbuilder/semantic-knowledge-graph/047be46655df96ff4b6e1c790436686a60f494f6/configs/solr/knowledge-graph/core.properties
--------------------------------------------------------------------------------
/configs/solr/solr.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
28 |
29 |
30 |
31 |
32 | ${host:}
33 | ${jetty.port:8983}
34 | ${hostContext:solr}
35 | ${zkClientTimeout:30000}
36 | ${genericCoreNodeNames:true}
37 |
38 |
39 |
41 | ${socketTimeout:0}
42 | ${connTimeout:0}
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/knowledge-graph/.gitignore:
--------------------------------------------------------------------------------
1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
2 |
3 | *.iml
4 |
5 | ## Directory-based project format:
6 | .idea/
7 | # if you remove the above rule, at least ignore the following:
8 |
9 | # User-specific stuff:
10 | # .idea/workspace.xml
11 | # .idea/tasks.xml
12 | # .idea/dictionaries
13 |
14 | # Sensitive or high-churn files:
15 | # .idea/dataSources.ids
16 | # .idea/dataSources.xml
17 | # .idea/sqlDataSources.xml
18 | # .idea/dynamic.xml
19 | # .idea/uiDesigner.xml
20 |
21 | # Gradle:
22 | # .idea/gradle.xml
23 | # .idea/libraries
24 |
25 | # Mongo Explorer plugin:
26 | # .idea/mongoSettings.xml
27 |
28 | ## File-based project format:
29 | *.ipr
30 | *.iws
31 |
32 | ## Plugin-specific files:
33 |
34 | # IntelliJ
35 | /out/
36 |
37 | # mpeltonen/sbt-idea plugin
38 | .idea_modules/
39 |
40 | # JIRA plugin
41 | atlassian-ide-plugin.xml
42 |
43 | # Crashlytics plugin (for Android Studio and IntelliJ)
44 | com_crashlytics_export_strings.xml
45 | crashlytics.properties
46 | crashlytics-build.properties
47 |
48 | #Maven
49 | target/
50 | pom.xml.tag
51 | pom.xml.releaseBackup
52 | pom.xml.versionsBackup
53 | pom.xml.next
54 | release.properties
55 | dependency-reduced-pom.xml
56 | buildNumber.properties
57 |
--------------------------------------------------------------------------------
/knowledge-graph/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 |
8 | com.careerbuilder.relevancy
9 | knowledge-graph
10 | 1.0-SNAPSHOT
11 | jar
12 |
13 |
14 | semantic_knowledge_graph
15 | Ranks tags using corpus of tagged data
16 | 2016
17 |
18 |
19 | UTF-8
20 | 5.1.0
21 |
22 |
23 |
24 | 2.2.1
25 |
26 |
27 |
28 |
29 |
30 | org.apache.solr
31 | solr-test-framework
32 | ${solr.version}
33 | test
34 |
35 |
36 | org.apache.lucene
37 | lucene-test-framework
38 | ${solr.version}
39 | test
40 |
41 |
42 |
43 | org.apache.solr
44 | solr-core
45 | ${solr.version}
46 |
47 |
48 | org.slf4j
49 | slf4j-jdk14
50 |
51 |
52 | org.slf4j
53 | slf4j-log4j12
54 |
55 |
56 | log4j
57 | log4j
58 |
59 |
60 |
61 |
62 |
63 | org.apache.lucene
64 | lucene-core
65 | ${solr.version}
66 |
67 |
68 |
69 | org.apache.commons
70 | commons-lang3
71 | 3.4
72 |
73 |
74 | com.google.code.gson
75 | gson
76 | 1.7.1
77 |
78 |
79 | com.carrotsearch
80 | hppc
81 | 0.5.2
82 |
83 |
84 |
85 |
86 | org.slf4j
87 | slf4j-api
88 | 1.7.7
89 |
90 |
91 | org.slf4j
92 | jcl-over-slf4j
93 | 1.7.7
94 |
95 |
96 | ch.qos.logback
97 | logback-classic
98 | 1.1.2
99 | runtime
100 | true
101 |
102 |
103 | junit
104 | junit
105 | 4.11
106 |
107 |
108 | org.jmockit
109 | jmockit
110 | 1.8
111 |
112 |
113 |
114 |
115 |
116 |
117 | org.apache.maven.plugins
118 | maven-compiler-plugin
119 | 3.1
120 |
121 | 1.8
122 | 1.8
123 |
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-jar-plugin
129 | 2.4
130 |
131 |
132 |
133 | true
134 | true
135 |
136 |
137 |
138 |
139 |
140 | org.apache.maven.plugins
141 | maven-shade-plugin
142 | 1.6
143 |
144 |
145 | package
146 |
147 | shade
148 |
149 |
150 |
151 |
152 | com.google.code.gson:gson
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
--------------------------------------------------------------------------------
/knowledge-graph/src/main/java/com/careerbuilder/search/relevancy/FieldChecker.java:
--------------------------------------------------------------------------------
1 | package com.careerbuilder.search.relevancy;
2 |
3 | import org.apache.solr.common.SolrException;
4 | import org.apache.solr.request.SolrQueryRequest;
5 |
6 | public class FieldChecker {
7 |
8 | public static void checkField(SolrQueryRequest req, String inputField, String facetField) {
9 | try {
10 | req.getCore()
11 | .getLatestSchema()
12 | .getField(facetField).getName();
13 | } catch (SolrException e) {
14 | throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
15 | "Values of type \"" + inputField + "\" cannot be generated automatically or normalized " +
16 | "(adapted as \"" + facetField + "\")");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/knowledge-graph/src/main/java/com/careerbuilder/search/relevancy/KnowledgeGraphHandler.java:
--------------------------------------------------------------------------------
1 | package com.careerbuilder.search.relevancy;
2 |
3 | import com.careerbuilder.search.relevancy.model.ParameterSet;
4 | import com.careerbuilder.search.relevancy.model.KnowledgeGraphRequest;
5 | import com.careerbuilder.search.relevancy.model.KnowledgeGraphResponse;
6 | import com.google.common.io.CharStreams;
7 | import com.google.gson.Gson;
8 | import org.apache.lucene.analysis.util.ResourceLoader;
9 | import org.apache.solr.common.SolrException;
10 | import org.apache.solr.common.util.ContentStream;
11 | import org.apache.solr.common.util.NamedList;
12 | import org.apache.solr.handler.RequestHandlerBase;
13 | import org.apache.solr.request.SolrQueryRequest;
14 | import org.apache.solr.response.SolrQueryResponse;
15 |
16 | import java.io.IOException;
17 | import java.io.Reader;
18 | import java.util.Iterator;
19 |
20 |
21 | public class KnowledgeGraphHandler extends RequestHandlerBase
22 | {
23 | private ResourceLoader loader;
24 |
25 | @Override
26 | public void init(NamedList args) {
27 | super.init(args);
28 | }
29 |
30 | @Override
31 | public void handleRequestBody(SolrQueryRequest solrReq, SolrQueryResponse solrRsp)
32 | throws Exception {
33 | KnowledgeGraphRequest request = parsePost(solrReq);
34 | new RequestValidator(solrReq, request).validate();
35 | ParameterSet parameterSet = new ParameterSet(solrReq.getParams(), defaults, invariants);
36 | NodeContext context = new NodeContext(request, solrReq, parameterSet);
37 | RequestTreeRecurser recurser = new RequestTreeRecurser(context);
38 | KnowledgeGraphResponse response = new KnowledgeGraphResponse();
39 | response.data = recurser.score();
40 | solrRsp.add("relatednessResponse", response);
41 | }
42 |
43 | private KnowledgeGraphRequest parsePost(SolrQueryRequest request) throws IOException {
44 | String inputString = getPostString(request);
45 | try {
46 | return new Gson().fromJson(inputString, KnowledgeGraphRequest.class);
47 | } catch (Exception e) {
48 | throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.getMessage());
49 | }
50 | }
51 |
52 | private String getPostString(SolrQueryRequest request) throws IOException {
53 | Reader inputReader = null;
54 | Iterable streams = request.getContentStreams();
55 | if (streams != null) {
56 | Iterator iter = streams.iterator();
57 | if (iter.hasNext()) {
58 | inputReader = iter.next().getReader();
59 | }
60 | if (iter.hasNext()) {
61 | throwWithClassName(" does not support multiple ContentStreams");
62 | }
63 | }
64 | if (inputReader == null) {
65 | throwWithClassName(" requires POST data");
66 | }
67 | String inputString;
68 | inputString = CharStreams.toString(inputReader);
69 | inputReader.close();
70 | if(inputString.equals("") || inputString == null) {
71 | throwWithClassName(" requires POST data");
72 | }
73 | return inputString;
74 | }
75 |
76 | private void throwWithClassName(String msgAfterClassName) {
77 | throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
78 | getClass().getSimpleName()+ msgAfterClassName);
79 | }
80 |
81 | //////////////////////// SolrInfoMBeans methods //////////////////////
82 |
83 | @Override
84 | public String getDescription()
85 | {
86 | return "Ranks tags using corpus of tagged data";
87 | }
88 |
89 | @Override
90 | public String getSource() {
91 | return "$Source$";
92 | }
93 |
94 | @Override
95 | public String getVersion() {
96 | return "$Revision$";
97 | }
98 |
99 |
100 | }
--------------------------------------------------------------------------------
/knowledge-graph/src/main/java/com/careerbuilder/search/relevancy/NodeContext.java:
--------------------------------------------------------------------------------
1 | package com.careerbuilder.search.relevancy;
2 |
3 | import com.careerbuilder.search.relevancy.model.ParameterSet;
4 | import com.careerbuilder.search.relevancy.model.KnowledgeGraphRequest;
5 | import com.careerbuilder.search.relevancy.utility.ParseUtility;
6 | import org.apache.lucene.search.Query;
7 | import org.apache.solr.request.SolrQueryRequest;
8 | import org.apache.solr.search.*;
9 |
10 | import java.io.IOException;
11 | import java.util.List;
12 |
13 | public class NodeContext {
14 |
15 | public KnowledgeGraphRequest request;
16 | public SolrQueryRequest req;
17 | public ParameterSet parameterSet;
18 | public List queries;
19 | public List fgQueries;
20 | public List bgQueries;
21 | public DocListAndSet queryDomainList;
22 | public DocSet queryDomain;
23 | public DocSet fgDomain;
24 | public DocSet bgDomain;
25 |
26 | @Deprecated
27 | public NodeContext(KnowledgeGraphRequest request)
28 | {
29 | this.request = request;
30 | }
31 |
32 | @Deprecated
33 | public NodeContext(ParameterSet parameterSet)
34 | {
35 | this.parameterSet = parameterSet;
36 | }
37 |
38 | public NodeContext(KnowledgeGraphRequest request, SolrQueryRequest req, ParameterSet parameterSet) throws IOException
39 | {
40 | this.request = request;
41 | this.req = req;
42 | this.parameterSet = parameterSet;
43 | this.queries = ParseUtility.parseQueryStrings(request.queries, req);
44 | if(request.foreground_queries == null) {
45 | this.fgQueries = this.queries;
46 | }
47 | else {
48 | this.fgQueries = ParseUtility.parseQueryStrings(request.foreground_queries, req);
49 | }
50 | this.bgQueries = ParseUtility.parseQueryStrings(request.background_queries, req);
51 | this.queryDomain = req.getSearcher().getDocSet(queries);
52 | this.fgDomain= req.getSearcher().getDocSet(fgQueries);
53 | this.bgDomain = req.getSearcher().getDocSet(bgQueries);
54 | }
55 |
56 | // copy constructor
57 | public NodeContext(NodeContext parent, String filterQueryString) throws IOException
58 | {
59 | this.req = parent.req;
60 | this.request = parent.request;
61 | this.parameterSet = parent.parameterSet;
62 | this.queries = parent.queries;
63 | this.fgQueries = parent.fgQueries;
64 | this.bgQueries = parent.bgQueries;
65 | this.queryDomain = req.getSearcher().getDocSet(ParseUtility.parseQueryString(filterQueryString, req), parent.queryDomain);
66 | this.fgDomain= req.getSearcher().getDocSet(ParseUtility.parseQueryString(filterQueryString, req), parent.fgDomain);
67 | this.bgDomain= parent.bgDomain;
68 | }
69 |
70 | public NodeContext() {}
71 |
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/knowledge-graph/src/main/java/com/careerbuilder/search/relevancy/RecursionOp.java:
--------------------------------------------------------------------------------
1 | package com.careerbuilder.search.relevancy;
2 |
3 | import com.careerbuilder.search.relevancy.model.RequestNode;
4 | import com.careerbuilder.search.relevancy.model.ResponseNode;
5 |
6 | import java.io.IOException;
7 |
8 | public interface RecursionOp {
9 |
10 | ResponseNode [] transform(NodeContext nodeContext, RequestNode [] request, ResponseNode [] responses) throws IOException;
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/knowledge-graph/src/main/java/com/careerbuilder/search/relevancy/RequestTreeRecurser.java:
--------------------------------------------------------------------------------
1 | package com.careerbuilder.search.relevancy;
2 |
3 | import com.careerbuilder.search.relevancy.generation.NodeGenerator;
4 | import com.careerbuilder.search.relevancy.model.KnowledgeGraphRequest;
5 | import com.careerbuilder.search.relevancy.model.RequestNode;
6 | import com.careerbuilder.search.relevancy.model.ResponseNode;
7 | import com.careerbuilder.search.relevancy.model.ResponseValue;
8 | import com.careerbuilder.search.relevancy.normalization.NodeNormalizer;
9 | import com.careerbuilder.search.relevancy.scoring.NodeScorer;
10 |
11 | import java.io.IOException;
12 |
13 | public class RequestTreeRecurser {
14 |
15 | public static final int DEFAULT_REQUEST_LIMIT = 1;
16 |
17 | private KnowledgeGraphRequest request;
18 | private NodeContext baseContext;
19 | private RecursionOp normalizer;
20 | private RecursionOp generator;
21 | private RecursionOp scorer;
22 |
23 | public RequestTreeRecurser(NodeContext context) throws IOException {
24 | this(context, new NodeNormalizer(), new NodeGenerator(), new NodeScorer());
25 | }
26 |
27 | public RequestTreeRecurser(NodeContext context,
28 | RecursionOp normalizer,
29 | RecursionOp generator,
30 | RecursionOp scorer) throws IOException {
31 | this.normalizer = normalizer;
32 | this.generator = generator;
33 | this.scorer = scorer;
34 | this.request = context.request;
35 | this.baseContext = context;
36 | }
37 |
38 | public ResponseNode[] score() throws IOException {
39 | ResponseNode[] responses = null;
40 | if(request.compare != null) {
41 | setDefaults(request.compare);
42 | if(baseContext.request.normalize) {
43 | normalizer.transform(baseContext, request.compare, null);
44 | }
45 | responses = generator.transform(baseContext, request.compare, null);
46 | responses = scorer.transform(baseContext, request.compare, responses);
47 | for(int i = 0; i < request.compare.length; ++i) {
48 | recurse(baseContext, responses[i], request.compare[i].compare);
49 | }
50 | }
51 | return responses;
52 | }
53 |
54 | private void recurse(NodeContext parentContext, ResponseNode parentResponse, RequestNode[] requests) throws IOException {
55 | if(requests != null) {
56 | setDefaults(requests);
57 | for (ResponseValue value : parentResponse.values) {
58 | String query = value.value == null || value.value.equals("") ? "*" : value.value.toLowerCase();
59 | NodeContext context = new NodeContext(parentContext, parentResponse.type+":"+query);
60 | if(context.request.normalize) {
61 | normalizer.transform(context, requests, null);
62 | }
63 | ResponseNode [] responses = generator.transform(context, requests, null);
64 | value.compare = scorer.transform(context, requests, responses);
65 | for (int i = 0; i < requests.length; ++i) {
66 | recurse(context, value.compare[i], requests[i].compare);
67 | }
68 | }
69 | }
70 | }
71 |
72 | private void setDefaults(RequestNode [] requests)
73 | {
74 | for(RequestNode request: requests) {
75 | if (request.values == null || request.values.length == 0) {
76 | request.discover_values = true;
77 | }
78 | int limit = request.values == null || request.values.length == 0 ? DEFAULT_REQUEST_LIMIT : request.values.length;
79 | request.limit = request.limit == 0 ? limit : request.limit;
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/knowledge-graph/src/main/java/com/careerbuilder/search/relevancy/RequestValidator.java:
--------------------------------------------------------------------------------
1 | package com.careerbuilder.search.relevancy;
2 |
3 | import com.careerbuilder.search.relevancy.model.KnowledgeGraphRequest;
4 | import com.careerbuilder.search.relevancy.model.RequestNode;
5 | import org.apache.solr.common.SolrException;
6 | import org.apache.solr.request.SolrQueryRequest;
7 |
8 | public class RequestValidator {
9 |
10 | private KnowledgeGraphRequest request;
11 | private SolrQueryRequest solrRequest;
12 |
13 | public RequestValidator(SolrQueryRequest solrRequest, KnowledgeGraphRequest request)
14 | {
15 | this.request = request;
16 | this.solrRequest= solrRequest;
17 | }
18 |
19 | public void validate()
20 | {
21 | if(request.queries == null) {
22 | throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No queries supplied for generation / scoring");
23 | }
24 | if(request.compare == null || request.compare.length == 0) {
25 | throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Request contains no compare node or an empty compare node");
26 | }
27 | for(int i = 0; i < request.compare.length; ++i) {
28 | recurse(request.compare[i]);
29 | }
30 | }
31 |
32 | private void recurse(RequestNode requestNode)
33 | {
34 | if(requestNode.type == null || requestNode.type.equals("")) {
35 | throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "A request node contains empty or null type.");
36 | }
37 | FieldChecker.checkField(solrRequest, requestNode.type, requestNode.type);
38 |
39 | if(requestNode.compare != null) {
40 | for (int i = 0; i < requestNode.compare.length; ++i){
41 | recurse(requestNode.compare[i]);
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/knowledge-graph/src/main/java/com/careerbuilder/search/relevancy/generation/FacetFieldAdapter.java:
--------------------------------------------------------------------------------
1 | package com.careerbuilder.search.relevancy.generation;
2 |
3 | import com.careerbuilder.search.relevancy.FieldChecker;
4 | import com.careerbuilder.search.relevancy.NodeContext;
5 | import org.apache.solr.common.util.SimpleOrderedMap;
6 |
7 | public class FacetFieldAdapter {
8 |
9 | NodeContext context;
10 |
11 |
12 | public String field;
13 | public String baseField;
14 | private String facetFieldExtension;
15 | private String globalFacetFieldExtension;
16 | private String facetFieldDelimiter;
17 | private String facetFieldValueDelimiter;
18 | private String facetFieldKey;
19 |
20 | @Deprecated
21 | public FacetFieldAdapter(String field) {
22 | this.field = field;
23 | this.baseField = field;
24 | }
25 |
26 | public FacetFieldAdapter(NodeContext context, String field)
27 | {
28 | this.context = context;
29 | this.facetFieldKey = context.parameterSet.invariants.get(field + ".key", "");
30 | this.facetFieldExtension = context.parameterSet.invariants.get(field + ".facet-field", "");
31 | this.globalFacetFieldExtension = context.parameterSet.invariants.get("facet-field-extension", "");
32 | this.facetFieldDelimiter = context.parameterSet.invariants.get("facet-field-delimiter", "-");
33 | this.facetFieldValueDelimiter = context.parameterSet.invariants.get("facet-field-value-delimiter", "^");
34 | FieldChecker.checkField(context.req, field, field);
35 | this.baseField = field;
36 | this.field = buildField(field);
37 | }
38 |
39 | public SimpleOrderedMap getMapValue(SimpleOrderedMap