Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalheir committed Dec 12, 2021
1 parent 01c7e3c commit 982e0cd
Show file tree
Hide file tree
Showing 17 changed files with 1,800 additions and 3,228 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./ts-compiled/index";
export * from "./dist";
4,907 changes: 1,739 additions & 3,168 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "semiring",
"version": "1.2.7",
"main": "index.js",
"version": "1.3.0",
"main": "dist/index.js",
"types": "index.d.ts",
"repository": "[email protected]:digitalheir/semiring-js.git",
"author": {
Expand All @@ -23,23 +23,22 @@
"license": "MIT",
"dependencies": {},
"devDependencies": {
"@types/chai": "^4.0.4",
"@types/mocha": "^2.2.43",
"awesome-typescript-loader": "^3.0.0-beta.17",
"chai": "^4.1.2",
"copyfiles": "^1.0.0",
"mocha": "^3.2.0",
"rimraf": "^2.5.4",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"copyfiles": "^2.4.1",
"mocha": "^9.1.3",
"rimraf": "^3.0.2",
"ts-babel-node": "^1.1.1",
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"tslint-loader": "^3.3.0",
"typescript": "^2.1.5",
"webpack": "^3.5.6"
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"typescript": "^4.5.3",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1"
},
"scripts": {
"build": "webpack -p",
"build": "npx webpack",
"build:ts": "tsc",
"test": "mocha --compilers ts:ts-node/register,tsx:ts-node/register **/*.spec.ts"
"test": "mocha --require ts-node/register **/*.spec.ts"
}
}
2 changes: 1 addition & 1 deletion src/abstract-expression/arithmetic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import {ADD, MULTIPLY} from "../semirings/floating-point";
import {PlusExpression, TimesExpression} from "../expression/binary-function";

export class Multiplication extends TimesExpression<number> {
resolve(): number {
return MULTIPLY(this.left.resolve(), this.right.resolve());
Expand Down
2 changes: 1 addition & 1 deletion src/abstract-expression/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export class AtomicValue<T> implements Expression<T> {
let str = this._value.toString();
if (radix && isNumber(this._value)) str = this._value.toString(radix);

return "{" + str + "}";
return `{${str}}`;
}
}
21 changes: 11 additions & 10 deletions src/abstract-expression/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ export interface Expression<T> {
resolve(): T;
}

export class Identifity<T> implements Expression<T> {
readonly x: T;

constructor(x: T) {
this.x = x;
}
resolve(): T {
return this.x;
}
}
// export class Identifity<T> implements Expression<T> {
// readonly x: T;
//
// constructor(x: T) {
// this.x = x;
// }
//
// resolve(): T {
// return this.x;
// }
// }
2 changes: 1 addition & 1 deletion src/abstract-expression/number.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {AtomicValue} from "./atom";
export class Num extends AtomicValue<number> {
toString(radix?: number): string {
return "{" + this.value.toString(radix) + "}";
return `{${this.value.toString(radix)}}`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/expression/binary-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export abstract class BinaryFunction<T> implements Expression<T> {
}

export class WrappedBinaryFunction<T> extends BinaryFunction<T> {
private f: (x: T, y: T) => T;
private readonly f: (x: T, y: T) => T;

constructor(left: Expression<T>, right: Expression<T>, f: (x: T, y: T) => T) {
super(left, right);
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export * from "./semirings/tropical";
export * from "./semirings/floating-point";
export * from "./semirings/string";


/**
* Semiring defined on objects of type T.
*
Expand Down
4 changes: 2 additions & 2 deletions src/semirings/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export function AND(x: boolean, y: boolean) {
}

export const BooleanSemiring: Semiring<boolean> = {
additiveIdentity: false,
multiplicativeIdentity: true,
additiveIdentity: false,
multiplicativeIdentity: true,
plus: OR,
times: AND,
};
Expand Down
8 changes: 4 additions & 4 deletions src/semirings/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ADD} from "./floating-point";
import {ADD} from "./floating-point";
import {Semiring} from "../index";

export const LogSemiring: Semiring<number> = {
Expand All @@ -23,14 +23,14 @@ export const LogSemiring: Semiring<number> = {
};

export function fromProbability(x: number): number {
if (x > 1.0 || x < 0.0) throw new Error("Can't have probabilities >1.0 or <0.0: " + x);
if (x > 1.0 || x < 0.0) throw new Error(`Can't have probabilities >1.0 or <0.0: ${x}`);
return -Math.log(x);
}

export function toProbability(x: number): number {
const p = Math.exp(-x);
if (p > 1.0 || p < 0.0) throw new Error("Can't have probabilities >1.0 or <0.0: " + x);
if (p > 1.0 || p < 0.0) throw new Error(`Can't have probabilities >1.0 or <0.0: ${x}`);
return p;
}

export default LogSemiring ;
export default LogSemiring;
2 changes: 1 addition & 1 deletion src/semirings/tropical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const TropicalSemiring: Semiring<number> = {
times: ADD
};

export default TropicalSemiring;
// export default TropicalSemiring;
1 change: 1 addition & 0 deletions src/util/sets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function Equals(firstSet: Set<any>, secondSet: Set<any>) {

return sizeOfSecondSet == 0;
}

export function Product(firstSet: Set<any>, secondSet: Set<any>, combine: (x: any, y: any) => any) {
const returnSet: Set<any> = new Set();
firstSet.forEach(function (firstValue) {
Expand Down
2 changes: 1 addition & 1 deletion test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TropicalSemiring
} from "../src/index";
import {expect} from "chai";
import {createStringSemiring, FormalLanguage} from "../src/semirings/string";
import {createStringSemiring, FormalLanguage} from "../src";

const BooleanExpressionSemiring = makeDeferrable(BooleanSemiring);

Expand Down
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": false,
"lib": [
"es2016"
],
"target": "es5",
"lib": ["es2016"],
"target": "es2015",
"outDir": "ts-compiled"
},
"include": [
Expand Down
28 changes: 16 additions & 12 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const webpack = require('webpack');
const path = require('path');
const libraryName = 'semiring';

const plugins = [
new webpack.LoaderOptionsPlugin({
options: {
tslint: {
emitErrors: true,
failOnHint: true
}
// tslint: {
// emitErrors: true,
// failOnHint: true
// }
}
})
];

const outputFile = "index.js";
// outputFile = libraryName + '.' + VERSION + '.min.js';

Expand All @@ -19,24 +21,26 @@ var config = {
__dirname + '/src/index.ts'
],
devtool: 'source-map',
mode: "production",
output: {
path: path.join(__dirname, '/'),
filename: outputFile,
library: libraryName,
libraryTarget: 'umd',
libraryTarget: "umd",
umdNamedDefine: true
},
module: {
rules: [
{
enforce: 'pre',
test: /\.tsx?$/,
loader: 'tslint-loader',
exclude: /node_modules/
},
// {
// enforce: 'pre',
// test: /\.tsx?$/,
// loader: 'tslint-loader',
// exclude: /node_modules/
// },
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
loader: "ts-loader",
exclude: /node_modules/
}
]
Expand Down
7 changes: 3 additions & 4 deletions write-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
const base = 'dist/';
const pathPackage = base + "package.json";

const VERSION = require('./version').default;
const VERSION = "1.3.0";//require('./version').default;

const p = {
"name": "semiring",
Expand All @@ -21,9 +21,8 @@ function writePackageFileInDist() {
fs.writeFile(pathPackage, JSON.stringify(p, null, 2), "utf8", function (err) {
if (err) {
console.error(err);
}
else {
console.log("Written " + pathPackage);
} else {
console.log(`Written ${pathPackage}`);
}
});
}
Expand Down

0 comments on commit 982e0cd

Please sign in to comment.