Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nlptoolkit-annotatedsentence

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nlptoolkit-annotatedsentence - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

.idea/AnnotatedSentence-Js.iml

5

dist/AnnotatedSentence.d.ts

@@ -15,5 +15,6 @@ import { Sentence } from "nlptoolkit-corpus/dist/Sentence";

* Reads an annotated sentence from a text file.
* @param fileName File containing the annotated sentence.
* Converts a simple sentence to an annotated sentence.
* @param param File containing the annotated sentence. OR Simple sentence.
*/
constructor(fileName?: string);
constructor(param?: string);
/**

@@ -20,0 +21,0 @@ * Returns file name of the sentence

31

dist/AnnotatedSentence.js

@@ -21,13 +21,28 @@ (function (factory) {

* Reads an annotated sentence from a text file.
* @param fileName File containing the annotated sentence.
* Converts a simple sentence to an annotated sentence.
* @param param File containing the annotated sentence. OR Simple sentence.
*/
constructor(fileName) {
constructor(param) {
super();
if (fileName != undefined) {
this.file = fileName;
let data = fs.readFileSync(fileName, 'utf8');
let wordList = data.split("\n")[0].split(" ");
for (let word of wordList) {
this.words.push(new AnnotatedWord_1.AnnotatedWord(word));
this.words = [];
if (param !== undefined) {
if (param.includes(".txt")) {
let fileName = param;
if (fileName !== undefined) {
this.file = fileName;
let data = fs.readFileSync(fileName, 'utf8');
let wordList = data.split("\n")[0].split(" ");
for (let word of wordList) {
this.words.push(new AnnotatedWord_1.AnnotatedWord(word));
}
}
}
else {
let wordList = param.split(" ");
for (let word of wordList) {
if (word !== "") {
this.words.push(new AnnotatedWord_1.AnnotatedWord(word));
}
}
}
}

@@ -34,0 +49,0 @@ }

{
"name": "nlptoolkit-annotatedsentence",
"version": "1.0.4",
"version": "1.0.5",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,3 +16,3 @@ import {Sentence} from "nlptoolkit-corpus/dist/Sentence";

export class AnnotatedSentence extends Sentence{
export class AnnotatedSentence extends Sentence {

@@ -23,12 +23,26 @@ private file: string

* Reads an annotated sentence from a text file.
* @param fileName File containing the annotated sentence.
* Converts a simple sentence to an annotated sentence.
* @param param File containing the annotated sentence. OR Simple sentence.
*/
constructor(fileName?: string) {
constructor(param?: string) {
super();
if (fileName != undefined){
this.file = fileName
let data = fs.readFileSync(fileName, 'utf8')
let wordList = data.split("\n")[0].split(" ")
for (let word of wordList){
this.words.push(new AnnotatedWord(word))
this.words = []
if (param !== undefined) {
if (param.includes(".txt")) {
let fileName: string = param
if (fileName !== undefined) {
this.file = fileName;
let data: string = fs.readFileSync(fileName, 'utf8');
let wordList: string[] = data.split("\n")[0].split(" ");
for (let word of wordList) {
this.words.push(new AnnotatedWord(word));
}
}
} else {
let wordList: string[] = param.split(" ");
for (let word of wordList) {
if (word !== "") {
this.words.push(new AnnotatedWord(word));
}
}
}

@@ -42,3 +56,3 @@ }

*/
getFileName(): string{
getFileName(): string {
return this.file

@@ -51,12 +65,12 @@ }

*/
getShallowParseGroups(): Array<AnnotatedPhrase>{
getShallowParseGroups(): Array<AnnotatedPhrase> {
let shallowParseGroups = new Array<AnnotatedPhrase>();
let previousWord = undefined;
let current = undefined;
for (let i = 0; i < this.wordCount(); i++){
let annotatedWord = <AnnotatedWord> this.getWord(i);
if (previousWord == null){
for (let i = 0; i < this.wordCount(); i++) {
let annotatedWord = <AnnotatedWord>this.getWord(i);
if (previousWord == null) {
current = new AnnotatedPhrase(i, annotatedWord.getShallowParse());
} else {
if (previousWord.getShallowParse() != null && previousWord.getShallowParse() != annotatedWord.getShallowParse()){
if (previousWord.getShallowParse() != null && previousWord.getShallowParse() != annotatedWord.getShallowParse()) {
shallowParseGroups.push(current);

@@ -78,7 +92,7 @@ current = new AnnotatedPhrase(i, annotatedWord.getShallowParse());

*/
containsPredicate(): boolean{
for (let word of this.words){
let annotatedWord = <AnnotatedWord> word;
containsPredicate(): boolean {
for (let word of this.words) {
let annotatedWord = <AnnotatedWord>word;
if (annotatedWord.getArgument() != undefined &&
annotatedWord.getArgument().getArgumentType() == "PREDICATE"){
annotatedWord.getArgument().getArgumentType() == "PREDICATE") {
return true;

@@ -95,7 +109,7 @@ }

*/
containsFramePredicate(): boolean{
for (let word of this.words){
let annotatedWord = <AnnotatedWord> word;
containsFramePredicate(): boolean {
for (let word of this.words) {
let annotatedWord = <AnnotatedWord>word;
if (annotatedWord.getFrameElement() != undefined &&
annotatedWord.getFrameElement().getFrameElementType() == "PREDICATE"){
annotatedWord.getFrameElement().getFrameElementType() == "PREDICATE") {
return true;

@@ -107,8 +121,8 @@ }

updateConnectedPredicate(previousId: string, currentId: string): boolean{
updateConnectedPredicate(previousId: string, currentId: string): boolean {
let modified = false;
for (let word of this.words){
let annotatedWord = <AnnotatedWord> word;
for (let word of this.words) {
let annotatedWord = <AnnotatedWord>word;
if (annotatedWord.getArgument() != undefined && annotatedWord.getArgument().getId() != null &&
annotatedWord.getArgument().getId() == previousId){
annotatedWord.getArgument().getId() == previousId) {
annotatedWord.setArgument(annotatedWord.getArgument().getArgumentType() + "$" + currentId);

@@ -118,3 +132,3 @@ modified = true;

if (annotatedWord.getFrameElement() != undefined && annotatedWord.getFrameElement().getId() != null &&
annotatedWord.getFrameElement().getId() == previousId){
annotatedWord.getFrameElement().getId() == previousId) {
annotatedWord.setFrameElement(annotatedWord.getFrameElement().getFrameElementType() + "$" + annotatedWord.getFrameElement().getFrame() + "$" + currentId);

@@ -135,17 +149,17 @@ modified = true;

*/
predicateCandidates(framesetList: FramesetList): Array<AnnotatedWord>{
predicateCandidates(framesetList: FramesetList): Array<AnnotatedWord> {
let candidateList = new Array<AnnotatedWord>();
for (let word of this.words){
let annotatedWord = <AnnotatedWord> word;
for (let word of this.words) {
let annotatedWord = <AnnotatedWord>word;
if (annotatedWord.getParse() != undefined && annotatedWord.getParse().isVerb() &&
annotatedWord.getSemantic() != undefined && framesetList.frameExists(annotatedWord.getSemantic())){
annotatedWord.getSemantic() != undefined && framesetList.frameExists(annotatedWord.getSemantic())) {
candidateList.push(annotatedWord);
}
}
for (let i = 0; i < 2; i++){
for (let j = 0; j < this.words.length - i - 1; j++){
let annotatedWord = <AnnotatedWord> this.words[j];
let nextAnnotatedWord = <AnnotatedWord> this.words[j + 1];
for (let i = 0; i < 2; i++) {
for (let j = 0; j < this.words.length - i - 1; j++) {
let annotatedWord = <AnnotatedWord>this.words[j];
let nextAnnotatedWord = <AnnotatedWord>this.words[j + 1];
if (!candidateList.includes(annotatedWord) && candidateList.includes(nextAnnotatedWord) &&
annotatedWord.getSemantic() != undefined && annotatedWord.getSemantic() == nextAnnotatedWord.getSemantic()){
annotatedWord.getSemantic() != undefined && annotatedWord.getSemantic() == nextAnnotatedWord.getSemantic()) {
candidateList.push(annotatedWord);

@@ -166,17 +180,17 @@ }

*/
predicateFrameCandidates(frameNet: FrameNet): Array<AnnotatedWord>{
predicateFrameCandidates(frameNet: FrameNet): Array<AnnotatedWord> {
let candidateList = new Array<AnnotatedWord>();
for (let word of this.words){
let annotatedWord = <AnnotatedWord> word;
for (let word of this.words) {
let annotatedWord = <AnnotatedWord>word;
if (annotatedWord.getParse() != undefined && annotatedWord.getParse().isVerb() &&
annotatedWord.getSemantic() != undefined && frameNet.lexicalUnitExists(annotatedWord.getSemantic())){
annotatedWord.getSemantic() != undefined && frameNet.lexicalUnitExists(annotatedWord.getSemantic())) {
candidateList.push(annotatedWord);
}
}
for (let i = 0; i < 2; i++){
for (let j = 0; j < this.words.length - i - 1; j++){
let annotatedWord = <AnnotatedWord> this.words[j];
let nextAnnotatedWord = <AnnotatedWord> this.words[j + 1];
for (let i = 0; i < 2; i++) {
for (let j = 0; j < this.words.length - i - 1; j++) {
let annotatedWord = <AnnotatedWord>this.words[j];
let nextAnnotatedWord = <AnnotatedWord>this.words[j + 1];
if (!candidateList.includes(annotatedWord) && candidateList.includes(nextAnnotatedWord) &&
annotatedWord.getSemantic() != undefined && annotatedWord.getSemantic() == nextAnnotatedWord.getSemantic()){
annotatedWord.getSemantic() != undefined && annotatedWord.getSemantic() == nextAnnotatedWord.getSemantic()) {
candidateList.push(annotatedWord);

@@ -194,10 +208,10 @@ }

*/
getPredicate(index: number): string{
let count1 = 0, count2 = 0;
getPredicate(index: number): string {
let count1 = 0, count2 = 0;
let data = "";
let word = new Array<AnnotatedWord>();
let parse = new Array<MorphologicalParse>();
if (index < this.wordCount()){
if (index < this.wordCount()) {
for (let i = 0; i < this.wordCount(); i++) {
word.push(<AnnotatedWord> this.getWord(i));
word.push(<AnnotatedWord>this.getWord(i));
parse.push(word[i].getParse());

@@ -208,3 +222,3 @@ }

parse[i].getPos() != undefined && parse[i].getRootPos() == "VERB" &&
parse[i].getPos() == "VERB"){
parse[i].getPos() == "VERB") {
count1 = index - i;

@@ -217,3 +231,3 @@ break;

parse[i].getPos() != undefined && parse[i].getRootPos() == "VERB" &&
parse[i].getPos() == "VERB"){
parse[i].getPos() == "VERB") {
count2 = i - index;

@@ -223,6 +237,5 @@ break;

}
if (count1 > count2){
if (count1 > count2) {
data = word[count1].getName();
}
else{
} else {
data = word[count2].getName();

@@ -238,5 +251,5 @@ }

*/
removeWord(index: number){
removeWord(index: number) {
for (let value of this.words) {
let word = <AnnotatedWord> value;
let word = <AnnotatedWord>value;
if (word.getUniversalDependency() != undefined) {

@@ -261,7 +274,7 @@ if (word.getUniversalDependency().to() == index + 1) {

*/
toStems(): string{
toStems(): string {
if (this.words.length > 0) {
let annotatedWord = <AnnotatedWord> this.words[0];
let annotatedWord = <AnnotatedWord>this.words[0];
let result
if (annotatedWord.getParse() != null){
if (annotatedWord.getParse() != null) {
result = annotatedWord.getParse().getWord().getName();

@@ -272,4 +285,4 @@ } else {

for (let i = 1; i < this.words.length; i++) {
annotatedWord = <AnnotatedWord> this.words[i];
if (annotatedWord.getParse() != undefined){
annotatedWord = <AnnotatedWord>this.words[i];
if (annotatedWord.getParse() != undefined) {
result = result + " " + annotatedWord.getParse().getWord().getName();

@@ -293,10 +306,10 @@ } else {

*/
toDependencyString(wordIndex: number): string{
toDependencyString(wordIndex: number): string {
let sentenceString = "";
let word = <AnnotatedWord> this.getWord(wordIndex);
for (let k = 0; k < this.words.length; k++){
if (wordIndex == k){
let word = <AnnotatedWord>this.getWord(wordIndex);
for (let k = 0; k < this.words.length; k++) {
if (wordIndex == k) {
sentenceString += " <b><font color=\"red\">" + this.words[k].getName() + "</font></b>";
} else {
if (k + 1 == word.getUniversalDependency().to()){
if (k + 1 == word.getUniversalDependency().to()) {
sentenceString += " <b><font color=\"blue\">" + this.words[k].getName() + "</font></b>";

@@ -317,8 +330,8 @@ } else {

*/
toShallowParseString(wordIndex: number): string{
toShallowParseString(wordIndex: number): string {
let sentenceString = "";
let word = <AnnotatedWord> this.getWord(wordIndex);
let word = <AnnotatedWord>this.getWord(wordIndex);
let startIndex = wordIndex - 1;
while (startIndex >= 0 && (<AnnotatedWord> this.words[startIndex]).getShallowParse() != undefined &&
(<AnnotatedWord> this.words[startIndex]).getShallowParse() == word.getShallowParse()){
while (startIndex >= 0 && (<AnnotatedWord>this.words[startIndex]).getShallowParse() != undefined &&
(<AnnotatedWord>this.words[startIndex]).getShallowParse() == word.getShallowParse()) {
startIndex--;

@@ -328,9 +341,9 @@ }

let endIndex = wordIndex + 1;
while (endIndex < this.words.length && (<AnnotatedWord> this.words[endIndex]).getShallowParse() != undefined &&
(<AnnotatedWord> this.words[endIndex]).getShallowParse() == word.getShallowParse()){
while (endIndex < this.words.length && (<AnnotatedWord>this.words[endIndex]).getShallowParse() != undefined &&
(<AnnotatedWord>this.words[endIndex]).getShallowParse() == word.getShallowParse()) {
endIndex++;
}
endIndex--;
for (let k = 0; k < this.words.length; k++){
if (k >= startIndex && k <= endIndex){
for (let k = 0; k < this.words.length; k++) {
if (k >= startIndex && k <= endIndex) {
sentenceString += " <b><font color=\"blue\">" + this.words[k].getName() + "</font></b>";

@@ -350,8 +363,8 @@ } else {

*/
toNamedEntityString(wordIndex: number): string{
toNamedEntityString(wordIndex: number): string {
let sentenceString = "";
let word = <AnnotatedWord> this.getWord(wordIndex);
let word = <AnnotatedWord>this.getWord(wordIndex);
let startIndex = wordIndex - 1;
while (startIndex >= 0 && (<AnnotatedWord> this.words[startIndex]).getNamedEntityType() != undefined &&
(<AnnotatedWord> this.words[startIndex]).getNamedEntityType() == word.getNamedEntityType()){
while (startIndex >= 0 && (<AnnotatedWord>this.words[startIndex]).getNamedEntityType() != undefined &&
(<AnnotatedWord>this.words[startIndex]).getNamedEntityType() == word.getNamedEntityType()) {
startIndex--;

@@ -361,9 +374,9 @@ }

let endIndex = wordIndex + 1;
while (endIndex < this.words.length && (<AnnotatedWord> this.words[endIndex]).getNamedEntityType() != undefined &&
(<AnnotatedWord> this.words[endIndex]).getNamedEntityType() == word.getNamedEntityType()){
while (endIndex < this.words.length && (<AnnotatedWord>this.words[endIndex]).getNamedEntityType() != undefined &&
(<AnnotatedWord>this.words[endIndex]).getNamedEntityType() == word.getNamedEntityType()) {
endIndex++;
}
endIndex--;
for (let k = 0; k < this.words.length; k++){
if (k >= startIndex && k <= endIndex){
for (let k = 0; k < this.words.length; k++) {
if (k >= startIndex && k <= endIndex) {
sentenceString += " <b><font color=\"blue\">" + this.words[k].getName() + "</font></b>";

@@ -377,8 +390,8 @@ } else {

compareParses(sentence: AnnotatedSentence): ParserEvaluationScore{
compareParses(sentence: AnnotatedSentence): ParserEvaluationScore {
let score = new ParserEvaluationScore();
for (let i = 0; i < this.wordCount(); i++){
let relation1 = (<AnnotatedWord> this.words[i]).getUniversalDependency();
let relation2 = (<AnnotatedWord> sentence.getWord(i)).getUniversalDependency();
if (relation1 != undefined && relation2 != undefined){
for (let i = 0; i < this.wordCount(); i++) {
let relation1 = (<AnnotatedWord>this.words[i]).getUniversalDependency();
let relation2 = (<AnnotatedWord>sentence.getWord(i)).getUniversalDependency();
if (relation1 != undefined && relation2 != undefined) {
score.add(relation1.compareRelations(relation2));

@@ -390,4 +403,4 @@ }

private static addAll(result: Array<Literal>, toBeAdded: Array<Literal>){
for (let literal of toBeAdded){
private static addAll(result: Array<Literal>, toBeAdded: Array<Literal>) {
for (let literal of toBeAdded) {
result.push(literal)

@@ -397,4 +410,4 @@ }

private addAll(result: Array<SynSet>, toBeAdded: Array<SynSet>){
for (let synSet of toBeAdded){
private addAll(result: Array<SynSet>, toBeAdded: Array<SynSet>) {
for (let synSet of toBeAdded) {
result.push(synSet)

@@ -404,5 +417,5 @@ }

getUniversalDependencyFormat(path?: string): string{
getUniversalDependencyFormat(path?: string): string {
let result
if (path != undefined){
if (path != undefined) {
result = "# sent_id = " + path + this.getFileName() + "\n" + "# text = " + this.toWords() + "\n";

@@ -412,4 +425,4 @@ } else {

}
for (let i = 0; i < this.wordCount(); i++){
let word = <AnnotatedWord> this.getWord(i);
for (let i = 0; i < this.wordCount(); i++) {
let word = <AnnotatedWord>this.getWord(i);
result += (i + 1) + "\t" + word.getUniversalDependencyFormat(this.wordCount()) + "\n";

@@ -431,4 +444,4 @@ }

*/
constructLiterals(wordNet: WordNet, fsm: FsmMorphologicalAnalyzer, wordIndex: number): Array<Literal>{
let word = <AnnotatedWord> this.getWord(wordIndex);
constructLiterals(wordNet: WordNet, fsm: FsmMorphologicalAnalyzer, wordIndex: number): Array<Literal> {
let word = <AnnotatedWord>this.getWord(wordIndex);
let possibleLiterals = new Array<Literal>();

@@ -442,5 +455,5 @@ let morphologicalParse = word.getParse();

if (this.wordCount() > wordIndex + 1) {
firstSucceedingWord = <AnnotatedWord> this.getWord(wordIndex + 1);
firstSucceedingWord = <AnnotatedWord>this.getWord(wordIndex + 1);
if (this.wordCount() > wordIndex + 2) {
secondSucceedingWord = <AnnotatedWord> this.getWord(wordIndex + 2);
secondSucceedingWord = <AnnotatedWord>this.getWord(wordIndex + 2);
}

@@ -467,8 +480,8 @@ }

*/
constructSynSets(wordNet: WordNet, fsm: FsmMorphologicalAnalyzer, wordIndex: number): Array<SynSet>{
let word = <AnnotatedWord> this.getWord(wordIndex);
constructSynSets(wordNet: WordNet, fsm: FsmMorphologicalAnalyzer, wordIndex: number): Array<SynSet> {
let word = <AnnotatedWord>this.getWord(wordIndex);
let possibleSynSets = new Array<SynSet>();
let morphologicalParse = word.getParse();
let metamorphicParse = word.getMetamorphicParse();
let toBeAdded : Array<SynSet> = wordNet.constructSynSets(morphologicalParse.getWord().getName(), morphologicalParse, metamorphicParse, fsm);
let toBeAdded: Array<SynSet> = wordNet.constructSynSets(morphologicalParse.getWord().getName(), morphologicalParse, metamorphicParse, fsm);
this.addAll(possibleSynSets, toBeAdded);

@@ -480,11 +493,11 @@ let firstPrecedingWord = undefined;

if (wordIndex > 0) {
firstPrecedingWord = <AnnotatedWord> this.getWord(wordIndex - 1);
firstPrecedingWord = <AnnotatedWord>this.getWord(wordIndex - 1);
if (wordIndex > 1) {
secondPrecedingWord = <AnnotatedWord> this.getWord(wordIndex - 2);
secondPrecedingWord = <AnnotatedWord>this.getWord(wordIndex - 2);
}
}
if (this.wordCount() > wordIndex + 1) {
firstSucceedingWord = <AnnotatedWord> this.getWord(wordIndex + 1);
firstSucceedingWord = <AnnotatedWord>this.getWord(wordIndex + 1);
if (this.wordCount() > wordIndex + 2) {
secondSucceedingWord = <AnnotatedWord> this.getWord(wordIndex + 2);
secondSucceedingWord = <AnnotatedWord>this.getWord(wordIndex + 2);
}

@@ -501,3 +514,3 @@ }

if (firstPrecedingWord != undefined && firstSucceedingWord != undefined) {
toBeAdded = wordNet.constructIdiomSynSets(fsm, firstPrecedingWord.getParse(), firstPrecedingWord.getMetamorphicParse(), word.getParse(), word.getMetamorphicParse(), firstSucceedingWord.getParse(), firstSucceedingWord.getMetamorphicParse())
toBeAdded = wordNet.constructIdiomSynSets(fsm, firstPrecedingWord.getParse(), firstPrecedingWord.getMetamorphicParse(), word.getParse(), word.getMetamorphicParse(), firstSucceedingWord.getParse(), firstSucceedingWord.getMetamorphicParse())
this.addAll(possibleSynSets, toBeAdded);

@@ -504,0 +517,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc