Skip to content

Commit

Permalink
More SemOpenAlex namespace support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Hale committed Nov 1, 2023
1 parent 237b138 commit efd28d6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public final class TableConfig {
static final int VERSION_4_6_2 = 462;
static final int VERSION_4_7 = 470;
static final int VERSION_4_9 = 490;
static final int CURRENT_VERSION = VERSION_4_9;
static final int VERSION_4_9_1 = 491;
static final int CURRENT_VERSION = VERSION_4_9_1;

public static final String ID_HASH = "halyard.id.hash";
public static final String ID_JAVA_HASH = "halyard.id.javaHash";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.msd.gin.halyard.vocab;

import com.msd.gin.halyard.common.AbstractIRIEncodingNamespace;
import com.msd.gin.halyard.common.ValueIO;

import java.nio.ByteBuffer;

public class IntegerPairNamespace extends AbstractIRIEncodingNamespace {
private static final long serialVersionUID = 571723932297421854L;

private final String sep1;
private final String sep2;

IntegerPairNamespace(String prefix, String ns, String sep1, String sep2) {
super(prefix, ns);
this.sep1 = sep1;
this.sep2 = sep2;
}

@Override
public ByteBuffer writeBytes(String localName, ByteBuffer b) {
int start1 = sep1.length();
int end1 = localName.indexOf(sep2, start1);
if (end1 == -1) {
throw new IllegalArgumentException("Unexpected input: "+localName);
}
int start2 = end1 + sep2.length();
int start = b.position();
b = ValueIO.ensureCapacity(b, 1);
b.position(start + 1);
b = ValueIO.writeCompressedInteger(localName.substring(start1, end1), b);
int len1 = b.position() - start - 1;
b = ValueIO.writeCompressedInteger(localName.substring(start2), b);
b.put(start, (byte)len1);
return b;
}

@Override
public String readBytes(ByteBuffer b) {
int len1 = b.get();
int originalLimit = b.limit();
b.limit(b.position() + len1);
String first = ValueIO.readCompressedInteger(b);
b.limit(originalLimit);
String second = ValueIO.readCompressedInteger(b);
return sep1 + first + sep2 + second;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ public final class SEMOPENALEX implements Vocabulary {
public static final String WORK_NAMESPACE = "https://semopenalex.org/work/";
public static final String AUTHOR_NAMESPACE = "https://semopenalex.org/author/";
public static final String INSTITUTION_NAMESPACE = "https://semopenalex.org/institution/";
public static final String AUTHOR_POSITION_NAMESPACE = "https://semopenalex.org/authorposition/";
public static final String CONCEPT_SCORE_NAMESPACE = "https://semopenalex.org/conceptscore/";
public static final String COUNTS_BY_YEAR_NAMESPACE = "https://semopenalex.org/countsbyyear/";
public static final String LOCATION_NAMESPACE = "https://semopenalex.org/location/";
public static final Namespace CLASS_NS = new SimpleNamespace("soa_class", CLASS_NAMESPACE);
public static final Namespace PROPERTY_NS = new SimpleNamespace("soa_prop", PROPERTY_NAMESPACE);
public static final Namespace CONCEPT_NS = new PrefixedIntegerNamespace("soa_concept", CONCEPT_NAMESPACE, "C");
public static final Namespace WORK_NS = new PrefixedIntegerNamespace("soa_work", WORK_NAMESPACE, "W");
public static final Namespace AUTHOR_NS = new PrefixedIntegerNamespace("soa_auth", AUTHOR_NAMESPACE, "A");
public static final Namespace INSTITUTION_NS = new PrefixedIntegerNamespace("soa_inst", INSTITUTION_NAMESPACE, "I");
public static final Namespace AUTHOR_POSITION_NS = new IntegerPairNamespace("soa_ap", AUTHOR_POSITION_NAMESPACE, "W", "A");
public static final Namespace CONCEPT_SCORE_NS = new IntegerPairNamespace("soa_cs", CONCEPT_SCORE_NAMESPACE, "W", "C");
public static final Namespace COUNTS_BY_YEAR_NS = new PrefixedIntegerNamespace("soa_cby", COUNTS_BY_YEAR_NAMESPACE, "P");
public static final Namespace LOCATION_NS = new PrefixedIntegerNamespace("soa_loc", LOCATION_NAMESPACE, "W");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.msd.gin.halyard.common;

import com.msd.gin.halyard.vocab.HALYARD;
import com.msd.gin.halyard.vocab.SEMOPENALEX;
import com.msd.gin.halyard.vocab.WIKIDATA;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -80,6 +81,7 @@ private static List<Value> createData(ValueFactory vf) {
vf.createIRI(WIKIDATA.WDV_NAMESPACE, "400f9abd3fd761c62af23dbe8f8432158a6ce272"),
vf.createIRI(WIKIDATA.WDV_NAMESPACE, "invalid"),
vf.createIRI(WIKIDATA.WDV_NAMESPACE+"400f9abd3fd761c62af23dbe8f8432158a6ce272/"),
vf.createIRI(SEMOPENALEX.AUTHOR_POSITION_NAMESPACE+"W10986400A2001695"),
vf.createIRI("urn:uuid:8104c873-b648-44de-aaee-cb65f1dcafbb")
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.msd.gin.halyard.common;

import com.msd.gin.halyard.vocab.HALYARD;
import com.msd.gin.halyard.vocab.SEMOPENALEX;
import com.msd.gin.halyard.vocab.WIKIDATA;

import java.math.BigDecimal;
Expand Down Expand Up @@ -89,6 +90,7 @@ static List<Object[]> createData(ValueFactory vf) {
new Object[] {vf.createIRI(WIKIDATA.WDV_NAMESPACE, "400f9abd3fd761c62af23dbe8f8432158a6ce272"), ValueIO.ENCODED_IRI_TYPE},
new Object[] {vf.createIRI(WIKIDATA.WDV_NAMESPACE, "invalid"), ValueIO.NAMESPACE_HASH_TYPE},
new Object[] {vf.createIRI(WIKIDATA.WDV_NAMESPACE+"400f9abd3fd761c62af23dbe8f8432158a6ce272/"), ValueIO.END_SLASH_ENCODED_IRI_TYPE},
new Object[] {vf.createIRI(SEMOPENALEX.AUTHOR_POSITION_NAMESPACE+"W10986400A2001695"), ValueIO.ENCODED_IRI_TYPE},
new Object[] {vf.createIRI("urn:uuid:8104c873-b648-44de-aaee-cb65f1dcafbb"), ValueIO.ENCODED_IRI_TYPE}
);
}
Expand Down

0 comments on commit efd28d6

Please sign in to comment.